@perplexity-ai/mcp-server 0.2.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +176 -46
  3. package/compat.d.mts +58 -0
  4. package/compat.d.mts.map +1 -0
  5. package/compat.d.ts +58 -0
  6. package/compat.d.ts.map +1 -0
  7. package/compat.js +387 -0
  8. package/compat.js.map +1 -0
  9. package/compat.mjs +378 -0
  10. package/compat.mjs.map +1 -0
  11. package/dynamic-tools.d.mts +12 -0
  12. package/dynamic-tools.d.mts.map +1 -0
  13. package/dynamic-tools.d.ts +12 -0
  14. package/dynamic-tools.d.ts.map +1 -0
  15. package/dynamic-tools.js +135 -0
  16. package/dynamic-tools.js.map +1 -0
  17. package/dynamic-tools.mjs +132 -0
  18. package/dynamic-tools.mjs.map +1 -0
  19. package/filtering.d.mts +2 -0
  20. package/filtering.d.mts.map +1 -0
  21. package/filtering.d.ts +2 -0
  22. package/filtering.d.ts.map +1 -0
  23. package/filtering.js +20 -0
  24. package/filtering.js.map +1 -0
  25. package/filtering.mjs +13 -0
  26. package/filtering.mjs.map +1 -0
  27. package/headers.d.mts +4 -0
  28. package/headers.d.mts.map +1 -0
  29. package/headers.d.ts +4 -0
  30. package/headers.d.ts.map +1 -0
  31. package/headers.js +22 -0
  32. package/headers.js.map +1 -0
  33. package/headers.mjs +18 -0
  34. package/headers.mjs.map +1 -0
  35. package/http.d.mts +9 -0
  36. package/http.d.mts.map +1 -0
  37. package/http.d.ts +9 -0
  38. package/http.d.ts.map +1 -0
  39. package/http.js +108 -0
  40. package/http.js.map +1 -0
  41. package/http.mjs +100 -0
  42. package/http.mjs.map +1 -0
  43. package/index.d.mts +3 -0
  44. package/index.d.mts.map +1 -0
  45. package/index.d.ts +3 -0
  46. package/index.d.ts.map +1 -0
  47. package/index.js +91 -0
  48. package/index.js.map +1 -0
  49. package/index.mjs +89 -0
  50. package/index.mjs.map +1 -0
  51. package/options.d.mts +18 -0
  52. package/options.d.mts.map +1 -0
  53. package/options.d.ts +18 -0
  54. package/options.d.ts.map +1 -0
  55. package/options.js +415 -0
  56. package/options.js.map +1 -0
  57. package/options.mjs +408 -0
  58. package/options.mjs.map +1 -0
  59. package/package.json +156 -37
  60. package/server.d.mts +35 -0
  61. package/server.d.mts.map +1 -0
  62. package/server.d.ts +35 -0
  63. package/server.d.ts.map +1 -0
  64. package/server.js +166 -0
  65. package/server.js.map +1 -0
  66. package/server.mjs +152 -0
  67. package/server.mjs.map +1 -0
  68. package/src/compat.ts +483 -0
  69. package/src/dynamic-tools.ts +159 -0
  70. package/src/filtering.ts +14 -0
  71. package/src/headers.ts +23 -0
  72. package/src/http.ts +127 -0
  73. package/src/index.ts +108 -0
  74. package/src/options.ts +453 -0
  75. package/src/server.ts +201 -0
  76. package/src/stdio.ts +13 -0
  77. package/src/tools/chat/completions/create-chat-completions.ts +1360 -0
  78. package/src/tools/index.ts +73 -0
  79. package/src/tools/search/create-search.ts +89 -0
  80. package/src/tools/types.ts +103 -0
  81. package/src/tools.ts +1 -0
  82. package/src/tsconfig.json +11 -0
  83. package/stdio.d.mts +3 -0
  84. package/stdio.d.mts.map +1 -0
  85. package/stdio.d.ts +3 -0
  86. package/stdio.d.ts.map +1 -0
  87. package/stdio.js +14 -0
  88. package/stdio.js.map +1 -0
  89. package/stdio.mjs +10 -0
  90. package/stdio.mjs.map +1 -0
  91. package/tools/chat/completions/create-chat-completions.d.mts +45 -0
  92. package/tools/chat/completions/create-chat-completions.d.mts.map +1 -0
  93. package/tools/chat/completions/create-chat-completions.d.ts +45 -0
  94. package/tools/chat/completions/create-chat-completions.d.ts.map +1 -0
  95. package/tools/chat/completions/create-chat-completions.js +1357 -0
  96. package/tools/chat/completions/create-chat-completions.js.map +1 -0
  97. package/tools/chat/completions/create-chat-completions.mjs +1353 -0
  98. package/tools/chat/completions/create-chat-completions.mjs.map +1 -0
  99. package/tools/index.d.mts +10 -0
  100. package/tools/index.d.mts.map +1 -0
  101. package/tools/index.d.ts +10 -0
  102. package/tools/index.d.ts.map +1 -0
  103. package/tools/index.js +57 -0
  104. package/tools/index.js.map +1 -0
  105. package/tools/index.mjs +50 -0
  106. package/tools/index.mjs.map +1 -0
  107. package/tools/search/create-search.d.mts +45 -0
  108. package/tools/search/create-search.d.mts.map +1 -0
  109. package/tools/search/create-search.d.ts +45 -0
  110. package/tools/search/create-search.d.ts.map +1 -0
  111. package/tools/search/create-search.js +86 -0
  112. package/tools/search/create-search.js.map +1 -0
  113. package/tools/search/create-search.mjs +82 -0
  114. package/tools/search/create-search.mjs.map +1 -0
  115. package/tools/types.d.mts +51 -0
  116. package/tools/types.d.mts.map +1 -0
  117. package/tools/types.d.ts +51 -0
  118. package/tools/types.d.ts.map +1 -0
  119. package/tools/types.js +46 -0
  120. package/tools/types.js.map +1 -0
  121. package/tools/types.mjs +42 -0
  122. package/tools/types.mjs.map +1 -0
  123. package/tools.d.mts +2 -0
  124. package/tools.d.mts.map +1 -0
  125. package/tools.d.ts +2 -0
  126. package/tools.d.ts.map +1 -0
  127. package/tools.js +18 -0
  128. package/tools.js.map +1 -0
  129. package/tools.mjs +2 -0
  130. package/tools.mjs.map +1 -0
  131. package/dist/index.js +0 -427
package/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 perplexity
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Perplexity
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,83 +1,213 @@
1
- # Perplexity API Platform MCP Server
1
+ # Perplexity TypeScript MCP Server
2
2
 
3
- The official MCP server implementation for the Perplexity API Platform, providing AI assistants with real-time web search, reasoning, and research capabilities through Sonar models and the Search API.
3
+ It is generated with [Stainless](https://www.stainless.com/).
4
4
 
5
- Please refer to the official [DeepWiki page](https://deepwiki.com/ppl-ai/modelcontextprotocol) for assistance with implementation.
5
+ ## Installation
6
6
 
7
- ## Quick Start
7
+ ### Direct invocation
8
8
 
9
- ```bash
10
- npx @perplexity-ai/mcp-server
11
- ```
12
-
13
- ## Available Tools
14
-
15
- ### **perplexity_search**
16
- Direct web search using the Perplexity Search API. Returns ranked search results with metadata, perfect for finding current information.
9
+ You can run the MCP Server directly via `npx`:
17
10
 
18
- ### **perplexity_ask**
19
- General-purpose conversational AI with real-time web search using the `sonar-pro` model. Great for quick questions and everyday searches.
20
-
21
- ### **perplexity_research**
22
- Deep, comprehensive research using the `sonar-deep-research` model. Ideal for thorough analysis and detailed reports.
23
-
24
- ### **perplexity_reason**
25
- Advanced reasoning and problem-solving using the `sonar-reasoning-pro` model. Perfect for complex analytical tasks.
11
+ ```sh
12
+ export PERPLEXITY_API_KEY="My API Key"
13
+ npx -y @perplexity-ai/mcp-server@latest
14
+ ```
26
15
 
27
- ## Configuration
16
+ ### Via MCP Client
28
17
 
29
- ### Get Your API Key
30
- 1. Get your Perplexity API Key from the [API Portal](https://www.perplexity.ai/account/api/group)
31
- 2. Set it as an environment variable: `PERPLEXITY_API_KEY=your_key_here`
18
+ There is a partial list of existing clients at [modelcontextprotocol.io](https://modelcontextprotocol.io/clients). If you already
19
+ have a client, consult their documentation to install the MCP server.
32
20
 
33
- ### Claude Desktop
34
- Add to your `claude_desktop_config.json`:
21
+ For clients with a configuration JSON, it might look something like this:
35
22
 
36
23
  ```json
37
24
  {
38
25
  "mcpServers": {
39
- "perplexity": {
26
+ "perplexity_ai_perplexity_ai_api": {
40
27
  "command": "npx",
41
- "args": ["-y", "@perplexity-ai/mcp-server"],
28
+ "args": ["-y", "@perplexity-ai/mcp-server", "--client=claude", "--tools=all"],
42
29
  "env": {
43
- "PERPLEXITY_API_KEY": "your_key_here"
30
+ "PERPLEXITY_API_KEY": "My API Key"
44
31
  }
45
32
  }
46
33
  }
47
34
  }
48
35
  ```
49
36
 
50
- ### Cursor & Claude Code
51
- Use the HTTP-based configuration:
37
+ ## Exposing endpoints to your MCP Client
38
+
39
+ There are two ways to expose endpoints as tools in the MCP server:
40
+
41
+ 1. Exposing one tool per endpoint, and filtering as necessary
42
+ 2. Exposing a set of tools to dynamically discover and invoke endpoints from the API
43
+
44
+ ### Filtering endpoints and tools
45
+
46
+ You can run the package on the command line to discover and filter the set of tools that are exposed by the
47
+ MCP Server. This can be helpful for large APIs where including all endpoints at once is too much for your AI's
48
+ context window.
49
+
50
+ You can filter by multiple aspects:
51
+
52
+ - `--tool` includes a specific tool by name
53
+ - `--resource` includes all tools under a specific resource, and can have wildcards, e.g. `my.resource*`
54
+ - `--operation` includes just read (get/list) or just write operations
55
+
56
+ ### Dynamic tools
57
+
58
+ If you specify `--tools=dynamic` to the MCP server, instead of exposing one tool per endpoint in the API, it will
59
+ expose the following tools:
60
+
61
+ 1. `list_api_endpoints` - Discovers available endpoints, with optional filtering by search query
62
+ 2. `get_api_endpoint_schema` - Gets detailed schema information for a specific endpoint
63
+ 3. `invoke_api_endpoint` - Executes any endpoint with the appropriate parameters
64
+
65
+ This allows you to have the full set of API endpoints available to your MCP Client, while not requiring that all
66
+ of their schemas be loaded into context at once. Instead, the LLM will automatically use these tools together to
67
+ search for, look up, and invoke endpoints dynamically. However, due to the indirect nature of the schemas, it
68
+ can struggle to provide the correct properties a bit more than when tools are imported explicitly. Therefore,
69
+ you can opt-in to explicit tools, the dynamic tools, or both.
70
+
71
+ See more information with `--help`.
72
+
73
+ All of these command-line options can be repeated, combined together, and have corresponding exclusion versions (e.g. `--no-tool`).
74
+
75
+ Use `--list` to see the list of available tools, or see below.
76
+
77
+ ### Specifying the MCP Client
78
+
79
+ Different clients have varying abilities to handle arbitrary tools and schemas.
80
+
81
+ You can specify the client you are using with the `--client` argument, and the MCP server will automatically
82
+ serve tools and schemas that are more compatible with that client.
83
+
84
+ - `--client=<type>`: Set all capabilities based on a known MCP client
85
+
86
+ - Valid values: `openai-agents`, `claude`, `claude-code`, `cursor`
87
+ - Example: `--client=cursor`
88
+
89
+ Additionally, if you have a client not on the above list, or the client has gotten better
90
+ over time, you can manually enable or disable certain capabilities:
91
+
92
+ - `--capability=<name>`: Specify individual client capabilities
93
+ - Available capabilities:
94
+ - `top-level-unions`: Enable support for top-level unions in tool schemas
95
+ - `valid-json`: Enable JSON string parsing for arguments
96
+ - `refs`: Enable support for $ref pointers in schemas
97
+ - `unions`: Enable support for union types (anyOf) in schemas
98
+ - `formats`: Enable support for format validations in schemas (e.g. date-time, email)
99
+ - `tool-name-length=N`: Set maximum tool name length to N characters
100
+ - Example: `--capability=top-level-unions --capability=tool-name-length=40`
101
+ - Example: `--capability=top-level-unions,tool-name-length=40`
102
+
103
+ ### Examples
104
+
105
+ 1. Filter for read operations on cards:
106
+
107
+ ```bash
108
+ --resource=cards --operation=read
109
+ ```
110
+
111
+ 2. Exclude specific tools while including others:
112
+
113
+ ```bash
114
+ --resource=cards --no-tool=create_cards
115
+ ```
116
+
117
+ 3. Configure for Cursor client with custom max tool name length:
118
+
119
+ ```bash
120
+ --client=cursor --capability=tool-name-length=40
121
+ ```
122
+
123
+ 4. Complex filtering with multiple criteria:
124
+
125
+ ```bash
126
+ --resource=cards,accounts --operation=read --tag=kyc --no-tool=create_cards
127
+ ```
128
+
129
+ ## Running remotely
130
+
131
+ Launching the client with `--transport=http` launches the server as a remote server using Streamable HTTP transport. The `--port` setting can choose the port it will run on, and the `--socket` setting allows it to run on a Unix socket.
132
+
133
+ Authorization can be provided via the `Authorization` header using the Bearer scheme.
134
+
135
+ Additionally, authorization can be provided via the following headers:
136
+ | Header | Equivalent client option | Security scheme |
137
+ | ---------------------- | ------------------------ | --------------- |
138
+ | `x-perplexity-api-key` | `apiKey` | HTTPBearer |
139
+
140
+ A configuration JSON for this server might look like this, assuming the server is hosted at `http://localhost:3000`:
52
141
 
53
142
  ```json
54
143
  {
55
144
  "mcpServers": {
56
- "perplexity": {
57
- "type": "http",
58
- "url": "http://localhost:3000/mcp",
59
- "env": {
60
- "PERPLEXITY_API_KEY": "your_key_here"
145
+ "perplexity_ai_perplexity_ai_api": {
146
+ "url": "http://localhost:3000",
147
+ "headers": {
148
+ "Authorization": "Bearer <auth value>"
61
149
  }
62
150
  }
63
151
  }
64
152
  }
65
153
  ```
66
154
 
67
- ### Other MCP Clients
68
- For any MCP-compatible client, use:
155
+ The command-line arguments for filtering tools and specifying clients can also be used as query parameters in the URL.
156
+ For example, to exclude specific tools while including others, use the URL:
157
+
158
+ ```
159
+ http://localhost:3000?resource=cards&resource=accounts&no_tool=create_cards
160
+ ```
161
+
162
+ Or, to configure for the Cursor client, with a custom max tool name length, use the URL:
69
163
 
70
- ```bash
71
- npx @perplexity-ai/mcp-server
72
164
  ```
165
+ http://localhost:3000?client=cursor&capability=tool-name-length%3D40
166
+ ```
167
+
168
+ ## Importing the tools and server individually
169
+
170
+ ```js
171
+ // Import the server, generated endpoints, or the init function
172
+ import { server, endpoints, init } from "@perplexity-ai/mcp-server/server";
173
+
174
+ // import a specific tool
175
+ import createChatCompletions from "@perplexity-ai/mcp-server/tools/chat/completions/create-chat-completions";
176
+
177
+ // initialize the server and all endpoints
178
+ init({ server, endpoints });
179
+
180
+ // manually start server
181
+ const transport = new StdioServerTransport();
182
+ await server.connect(transport);
183
+
184
+ // or initialize your own server with specific tools
185
+ const myServer = new McpServer(...);
186
+
187
+ // define your own endpoint
188
+ const myCustomEndpoint = {
189
+ tool: {
190
+ name: 'my_custom_tool',
191
+ description: 'My custom tool',
192
+ inputSchema: zodToJsonSchema(z.object({ a_property: z.string() })),
193
+ },
194
+ handler: async (client: client, args: any) => {
195
+ return { myResponse: 'Hello world!' };
196
+ })
197
+ };
198
+
199
+ // initialize the server with your custom endpoints
200
+ init({ server: myServer, endpoints: [createChatCompletions, myCustomEndpoint] });
201
+ ```
202
+
203
+ ## Available Tools
73
204
 
74
- ## Troubleshooting
205
+ The following tools are available in this MCP server.
75
206
 
76
- - **API Key Issues**: Ensure `PERPLEXITY_API_KEY` is set correctly
77
- - **Connection Errors**: Check your internet connection and API key validity
78
- - **Tool Not Found**: Make sure the package is installed and the command path is correct
207
+ ### Resource `chat.completions`:
79
208
 
80
- For support, visit [community.perplexity.ai](https://community.perplexity.ai) or [file an issue](https://github.com/perplexityai/modelcontextprotocol/issues).
209
+ - `create_chat_completions` (`write`): Generate a chat completion response for the given conversation.
81
210
 
82
- ---
211
+ ### Resource `search`:
83
212
 
213
+ - `create_search` (`write`): Search the web and retrieve relevant web page contents.
package/compat.d.mts ADDED
@@ -0,0 +1,58 @@
1
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { z } from 'zod';
3
+ import { Endpoint } from "./tools.mjs";
4
+ export interface ClientCapabilities {
5
+ topLevelUnions: boolean;
6
+ validJson: boolean;
7
+ refs: boolean;
8
+ unions: boolean;
9
+ formats: boolean;
10
+ toolNameLength: number | undefined;
11
+ }
12
+ export declare const defaultClientCapabilities: ClientCapabilities;
13
+ export declare const ClientType: z.ZodEnum<["openai-agents", "claude", "claude-code", "cursor", "infer"]>;
14
+ export type ClientType = z.infer<typeof ClientType>;
15
+ export declare const knownClients: Record<Exclude<ClientType, 'infer'>, ClientCapabilities>;
16
+ /**
17
+ * Attempts to parse strings into JSON objects
18
+ */
19
+ export declare function parseEmbeddedJSON(args: Record<string, unknown>, schema: Record<string, unknown>): Record<string, unknown>;
20
+ export type JSONSchema = {
21
+ type?: string;
22
+ properties?: Record<string, JSONSchema>;
23
+ required?: string[];
24
+ anyOf?: JSONSchema[];
25
+ $ref?: string;
26
+ $defs?: Record<string, JSONSchema>;
27
+ [key: string]: any;
28
+ };
29
+ /**
30
+ * Truncates tool names to the specified length while ensuring uniqueness.
31
+ * If truncation would cause duplicate names, appends a number to make them unique.
32
+ */
33
+ export declare function truncateToolNames(names: string[], maxLength: number): Map<string, string>;
34
+ /**
35
+ * Removes top-level unions from a tool by splitting it into multiple tools,
36
+ * one for each variant in the union.
37
+ */
38
+ export declare function removeTopLevelUnions(tool: Tool): Tool[];
39
+ declare function findUsedDefs(schema: JSONSchema, defs: Record<string, JSONSchema>, visited?: Set<string>): Record<string, JSONSchema>;
40
+ export { findUsedDefs };
41
+ /**
42
+ * Inlines all $refs in a schema, eliminating $defs.
43
+ * If a circular reference is detected, the circular property is removed.
44
+ */
45
+ export declare function inlineRefs(schema: JSONSchema): JSONSchema;
46
+ /**
47
+ * Removes anyOf fields from a schema, using only the first variant.
48
+ */
49
+ export declare function removeAnyOf(schema: JSONSchema): JSONSchema;
50
+ /**
51
+ * Removes format fields from a schema and appends them to the description.
52
+ */
53
+ export declare function removeFormats(schema: JSONSchema, formatsCapability: boolean): JSONSchema;
54
+ /**
55
+ * Applies all compatibility transformations to the endpoints based on the provided capabilities.
56
+ */
57
+ export declare function applyCompatibilityTransformations(endpoints: Endpoint[], capabilities: ClientCapabilities): Endpoint[];
58
+ //# sourceMappingURL=compat.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.d.mts","sourceRoot":"","sources":["src/compat.ts"],"names":[],"mappings":"OAAO,EAAE,IAAI,EAAE,MAAM,o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F;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAyCvD;AAED,iBAAS,YAAY,CACnB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EAChC,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,GAC/B,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CA6B5B;AAGD,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAazD;AAoED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CA0C1D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,GAAG,UAAU,CAkCxF;AAED;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,QAAQ,EAAE,EACrB,YAAY,EAAE,kBAAkB,GAC/B,QAAQ,EAAE,CAiEZ"}
package/compat.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import { z } from 'zod';
3
+ import { Endpoint } from "./tools.js";
4
+ export interface ClientCapabilities {
5
+ topLevelUnions: boolean;
6
+ validJson: boolean;
7
+ refs: boolean;
8
+ unions: boolean;
9
+ formats: boolean;
10
+ toolNameLength: number | undefined;
11
+ }
12
+ export declare const defaultClientCapabilities: ClientCapabilities;
13
+ export declare const ClientType: z.ZodEnum<["openai-agents", "claude", "claude-code", "cursor", "infer"]>;
14
+ export type ClientType = z.infer<typeof ClientType>;
15
+ export declare const knownClients: Record<Exclude<ClientType, 'infer'>, ClientCapabilities>;
16
+ /**
17
+ * Attempts to parse strings into JSON objects
18
+ */
19
+ export declare function parseEmbeddedJSON(args: Record<string, unknown>, schema: Record<string, unknown>): Record<string, unknown>;
20
+ export type JSONSchema = {
21
+ type?: string;
22
+ properties?: Record<string, JSONSchema>;
23
+ required?: string[];
24
+ anyOf?: JSONSchema[];
25
+ $ref?: string;
26
+ $defs?: Record<string, JSONSchema>;
27
+ [key: string]: any;
28
+ };
29
+ /**
30
+ * Truncates tool names to the specified length while ensuring uniqueness.
31
+ * If truncation would cause duplicate names, appends a number to make them unique.
32
+ */
33
+ export declare function truncateToolNames(names: string[], maxLength: number): Map<string, string>;
34
+ /**
35
+ * Removes top-level unions from a tool by splitting it into multiple tools,
36
+ * one for each variant in the union.
37
+ */
38
+ export declare function removeTopLevelUnions(tool: Tool): Tool[];
39
+ declare function findUsedDefs(schema: JSONSchema, defs: Record<string, JSONSchema>, visited?: Set<string>): Record<string, JSONSchema>;
40
+ export { findUsedDefs };
41
+ /**
42
+ * Inlines all $refs in a schema, eliminating $defs.
43
+ * If a circular reference is detected, the circular property is removed.
44
+ */
45
+ export declare function inlineRefs(schema: JSONSchema): JSONSchema;
46
+ /**
47
+ * Removes anyOf fields from a schema, using only the first variant.
48
+ */
49
+ export declare function removeAnyOf(schema: JSONSchema): JSONSchema;
50
+ /**
51
+ * Removes format fields from a schema and appends them to the description.
52
+ */
53
+ export declare function removeFormats(schema: JSONSchema, formatsCapability: boolean): JSONSchema;
54
+ /**
55
+ * Applies all compatibility transformations to the endpoints based on the provided capabilities.
56
+ */
57
+ export declare function applyCompatibilityTransformations(endpoints: Endpoint[], capabilities: ClientCapabilities): Endpoint[];
58
+ //# sourceMappingURL=compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["src/compat.ts"],"names":[],"mappings":"OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC;OAClD,EAAE,CAAC,EAAE,MAAM,KAAK;OAChB,EAAE,QAAQ,EAAE;AAEnB,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,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