cas-parser-node-mcp 1.4.1 → 1.7.1

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 (215) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +29 -147
  3. package/auth.d.mts +4 -0
  4. package/auth.d.mts.map +1 -0
  5. package/auth.d.ts +4 -0
  6. package/auth.d.ts.map +1 -0
  7. package/{headers.js → auth.js} +2 -2
  8. package/auth.js.map +1 -0
  9. package/{headers.mjs → auth.mjs} +2 -2
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-types.d.mts +7 -7
  12. package/code-tool-types.d.mts.map +1 -1
  13. package/code-tool-types.d.ts +7 -7
  14. package/code-tool-types.d.ts.map +1 -1
  15. package/code-tool.d.mts +6 -3
  16. package/code-tool.d.mts.map +1 -1
  17. package/code-tool.d.ts +6 -3
  18. package/code-tool.d.ts.map +1 -1
  19. package/code-tool.js +86 -132
  20. package/code-tool.js.map +1 -1
  21. package/code-tool.mjs +86 -99
  22. package/code-tool.mjs.map +1 -1
  23. package/{tools/cas-generator/generate-cas-cas-generator.d.ts → docs-search-tool.d.mts} +17 -11
  24. package/docs-search-tool.d.mts.map +1 -0
  25. package/{tools/cas-generator/generate-cas-cas-generator.d.mts → docs-search-tool.d.ts} +17 -11
  26. package/docs-search-tool.d.ts.map +1 -0
  27. package/docs-search-tool.js +57 -0
  28. package/docs-search-tool.js.map +1 -0
  29. package/docs-search-tool.mjs +53 -0
  30. package/docs-search-tool.mjs.map +1 -0
  31. package/http.d.mts +9 -4
  32. package/http.d.mts.map +1 -1
  33. package/http.d.ts +9 -4
  34. package/http.d.ts.map +1 -1
  35. package/http.js +31 -34
  36. package/http.js.map +1 -1
  37. package/http.mjs +31 -34
  38. package/http.mjs.map +1 -1
  39. package/index.js +8 -40
  40. package/index.js.map +1 -1
  41. package/index.mjs +8 -40
  42. package/index.mjs.map +1 -1
  43. package/methods.d.mts +10 -0
  44. package/methods.d.mts.map +1 -0
  45. package/methods.d.ts +10 -0
  46. package/methods.d.ts.map +1 -0
  47. package/methods.js +167 -0
  48. package/methods.js.map +1 -0
  49. package/methods.mjs +163 -0
  50. package/methods.mjs.map +1 -0
  51. package/options.d.mts +5 -9
  52. package/options.d.mts.map +1 -1
  53. package/options.d.ts +5 -9
  54. package/options.d.ts.map +1 -1
  55. package/options.js +37 -362
  56. package/options.js.map +1 -1
  57. package/options.mjs +37 -362
  58. package/options.mjs.map +1 -1
  59. package/package.json +57 -79
  60. package/server.d.mts +5 -15
  61. package/server.d.mts.map +1 -1
  62. package/server.d.ts +5 -15
  63. package/server.d.ts.map +1 -1
  64. package/server.js +54 -87
  65. package/server.js.map +1 -1
  66. package/server.mjs +53 -82
  67. package/server.mjs.map +1 -1
  68. package/src/{headers.ts → auth.ts} +1 -1
  69. package/src/code-tool-types.ts +7 -5
  70. package/src/code-tool.ts +104 -117
  71. package/src/docs-search-tool.ts +65 -0
  72. package/src/http.ts +44 -40
  73. package/src/index.ts +9 -52
  74. package/src/methods.ts +188 -0
  75. package/src/options.ts +48 -384
  76. package/src/server.ts +63 -97
  77. package/src/stdio.ts +4 -4
  78. package/src/{tools/types.ts → types.ts} +13 -1
  79. package/src/util.ts +25 -0
  80. package/stdio.d.mts +1 -1
  81. package/stdio.d.mts.map +1 -1
  82. package/stdio.d.ts +1 -1
  83. package/stdio.d.ts.map +1 -1
  84. package/stdio.js +3 -3
  85. package/stdio.js.map +1 -1
  86. package/stdio.mjs +3 -3
  87. package/stdio.mjs.map +1 -1
  88. package/{tools/types.d.mts → types.d.mts} +2 -1
  89. package/types.d.mts.map +1 -0
  90. package/{tools/types.d.ts → types.d.ts} +2 -1
  91. package/types.d.ts.map +1 -0
  92. package/{tools/types.js → types.js} +12 -0
  93. package/types.js.map +1 -0
  94. package/{tools/types.mjs → types.mjs} +11 -0
  95. package/types.mjs.map +1 -0
  96. package/util.d.mts +4 -0
  97. package/util.d.mts.map +1 -0
  98. package/util.d.ts +4 -0
  99. package/util.d.ts.map +1 -0
  100. package/util.js +30 -0
  101. package/util.js.map +1 -0
  102. package/util.mjs +24 -0
  103. package/util.mjs.map +1 -0
  104. package/code-tool-paths.cjs +0 -6
  105. package/code-tool-paths.cjs.map +0 -1
  106. package/code-tool-paths.d.cts +0 -2
  107. package/code-tool-paths.d.cts.map +0 -1
  108. package/code-tool-worker.d.mts +0 -5
  109. package/code-tool-worker.d.mts.map +0 -1
  110. package/code-tool-worker.d.ts +0 -5
  111. package/code-tool-worker.d.ts.map +0 -1
  112. package/code-tool-worker.js +0 -45
  113. package/code-tool-worker.js.map +0 -1
  114. package/code-tool-worker.mjs +0 -40
  115. package/code-tool-worker.mjs.map +0 -1
  116. package/compat.d.mts +0 -58
  117. package/compat.d.mts.map +0 -1
  118. package/compat.d.ts +0 -58
  119. package/compat.d.ts.map +0 -1
  120. package/compat.js +0 -387
  121. package/compat.js.map +0 -1
  122. package/compat.mjs +0 -378
  123. package/compat.mjs.map +0 -1
  124. package/dynamic-tools.d.mts +0 -12
  125. package/dynamic-tools.d.mts.map +0 -1
  126. package/dynamic-tools.d.ts +0 -12
  127. package/dynamic-tools.d.ts.map +0 -1
  128. package/dynamic-tools.js +0 -135
  129. package/dynamic-tools.js.map +0 -1
  130. package/dynamic-tools.mjs +0 -132
  131. package/dynamic-tools.mjs.map +0 -1
  132. package/filtering.d.mts +0 -2
  133. package/filtering.d.mts.map +0 -1
  134. package/filtering.d.ts +0 -2
  135. package/filtering.d.ts.map +0 -1
  136. package/filtering.js +0 -20
  137. package/filtering.js.map +0 -1
  138. package/filtering.mjs +0 -13
  139. package/filtering.mjs.map +0 -1
  140. package/headers.d.mts +0 -4
  141. package/headers.d.mts.map +0 -1
  142. package/headers.d.ts +0 -4
  143. package/headers.d.ts.map +0 -1
  144. package/headers.js.map +0 -1
  145. package/headers.mjs.map +0 -1
  146. package/src/code-tool-paths.cts +0 -3
  147. package/src/code-tool-worker.ts +0 -46
  148. package/src/compat.ts +0 -483
  149. package/src/dynamic-tools.ts +0 -159
  150. package/src/filtering.ts +0 -14
  151. package/src/tools/cas-generator/generate-cas-cas-generator.ts +0 -67
  152. package/src/tools/cas-parser/cams-kfintech-cas-parser.ts +0 -47
  153. package/src/tools/cas-parser/cdsl-cas-parser.ts +0 -47
  154. package/src/tools/cas-parser/nsdl-cas-parser.ts +0 -47
  155. package/src/tools/cas-parser/smart-parse-cas-parser.ts +0 -47
  156. package/src/tools/index.ts +0 -79
  157. package/src/tools.ts +0 -1
  158. package/tools/cas-generator/generate-cas-cas-generator.d.mts.map +0 -1
  159. package/tools/cas-generator/generate-cas-cas-generator.d.ts.map +0 -1
  160. package/tools/cas-generator/generate-cas-cas-generator.js +0 -62
  161. package/tools/cas-generator/generate-cas-cas-generator.js.map +0 -1
  162. package/tools/cas-generator/generate-cas-cas-generator.mjs +0 -58
  163. package/tools/cas-generator/generate-cas-cas-generator.mjs.map +0 -1
  164. package/tools/cas-parser/cams-kfintech-cas-parser.d.mts +0 -45
  165. package/tools/cas-parser/cams-kfintech-cas-parser.d.mts.map +0 -1
  166. package/tools/cas-parser/cams-kfintech-cas-parser.d.ts +0 -45
  167. package/tools/cas-parser/cams-kfintech-cas-parser.d.ts.map +0 -1
  168. package/tools/cas-parser/cams-kfintech-cas-parser.js +0 -43
  169. package/tools/cas-parser/cams-kfintech-cas-parser.js.map +0 -1
  170. package/tools/cas-parser/cams-kfintech-cas-parser.mjs +0 -39
  171. package/tools/cas-parser/cams-kfintech-cas-parser.mjs.map +0 -1
  172. package/tools/cas-parser/cdsl-cas-parser.d.mts +0 -45
  173. package/tools/cas-parser/cdsl-cas-parser.d.mts.map +0 -1
  174. package/tools/cas-parser/cdsl-cas-parser.d.ts +0 -45
  175. package/tools/cas-parser/cdsl-cas-parser.d.ts.map +0 -1
  176. package/tools/cas-parser/cdsl-cas-parser.js +0 -43
  177. package/tools/cas-parser/cdsl-cas-parser.js.map +0 -1
  178. package/tools/cas-parser/cdsl-cas-parser.mjs +0 -39
  179. package/tools/cas-parser/cdsl-cas-parser.mjs.map +0 -1
  180. package/tools/cas-parser/nsdl-cas-parser.d.mts +0 -45
  181. package/tools/cas-parser/nsdl-cas-parser.d.mts.map +0 -1
  182. package/tools/cas-parser/nsdl-cas-parser.d.ts +0 -45
  183. package/tools/cas-parser/nsdl-cas-parser.d.ts.map +0 -1
  184. package/tools/cas-parser/nsdl-cas-parser.js +0 -43
  185. package/tools/cas-parser/nsdl-cas-parser.js.map +0 -1
  186. package/tools/cas-parser/nsdl-cas-parser.mjs +0 -39
  187. package/tools/cas-parser/nsdl-cas-parser.mjs.map +0 -1
  188. package/tools/cas-parser/smart-parse-cas-parser.d.mts +0 -45
  189. package/tools/cas-parser/smart-parse-cas-parser.d.mts.map +0 -1
  190. package/tools/cas-parser/smart-parse-cas-parser.d.ts +0 -45
  191. package/tools/cas-parser/smart-parse-cas-parser.d.ts.map +0 -1
  192. package/tools/cas-parser/smart-parse-cas-parser.js +0 -43
  193. package/tools/cas-parser/smart-parse-cas-parser.js.map +0 -1
  194. package/tools/cas-parser/smart-parse-cas-parser.mjs +0 -39
  195. package/tools/cas-parser/smart-parse-cas-parser.mjs.map +0 -1
  196. package/tools/index.d.mts +0 -10
  197. package/tools/index.d.mts.map +0 -1
  198. package/tools/index.d.ts +0 -10
  199. package/tools/index.d.ts.map +0 -1
  200. package/tools/index.js +0 -63
  201. package/tools/index.js.map +0 -1
  202. package/tools/index.mjs +0 -56
  203. package/tools/index.mjs.map +0 -1
  204. package/tools/types.d.mts.map +0 -1
  205. package/tools/types.d.ts.map +0 -1
  206. package/tools/types.js.map +0 -1
  207. package/tools/types.mjs.map +0 -1
  208. package/tools.d.mts +0 -2
  209. package/tools.d.mts.map +0 -1
  210. package/tools.d.ts +0 -2
  211. package/tools.d.ts.map +0 -1
  212. package/tools.js +0 -18
  213. package/tools.js.map +0 -1
  214. package/tools.mjs +0 -2
  215. package/tools.mjs.map +0 -1
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2025 Cas Parser
189
+ Copyright 2026 Cas Parser
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -10,6 +10,7 @@ You can run the MCP Server directly via `npx`:
10
10
 
11
11
  ```sh
12
12
  export CAS_PARSER_API_KEY="My API Key"
13
+ export CAS_PARSER_ENVIRONMENT="production"
13
14
  npx -y cas-parser-node-mcp@latest
14
15
  ```
15
16
 
@@ -25,106 +26,55 @@ For clients with a configuration JSON, it might look something like this:
25
26
  "mcpServers": {
26
27
  "cas_parser_node_api": {
27
28
  "command": "npx",
28
- "args": ["-y", "cas-parser-node-mcp", "--client=claude", "--tools=all"],
29
+ "args": ["-y", "cas-parser-node-mcp"],
29
30
  "env": {
30
- "CAS_PARSER_API_KEY": "My API Key"
31
+ "CAS_PARSER_API_KEY": "My API Key",
32
+ "CAS_PARSER_ENVIRONMENT": "production"
31
33
  }
32
34
  }
33
35
  }
34
36
  }
35
37
  ```
36
38
 
37
- ## Exposing endpoints to your MCP Client
39
+ ### Cursor
38
40
 
39
- There are two ways to expose endpoints as tools in the MCP server:
41
+ If you use Cursor, you can install the MCP server by using the button below. You will need to set your environment variables
42
+ in Cursor's `mcp.json`, which can be found in Cursor Settings > Tools & MCP > New MCP Server.
40
43
 
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
44
+ [![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=cas-parser-node-mcp&config=eyJuYW1lIjoiY2FzLXBhcnNlci1ub2RlLW1jcCIsInRyYW5zcG9ydCI6Imh0dHAiLCJ1cmwiOiJodHRwczovL2Nhcy1wYXJzZXIuc3RsbWNwLmNvbSIsImhlYWRlcnMiOnsieC1hcGkta2V5IjoiTXkgQVBJIEtleSJ9fQ)
43
45
 
44
- ### Filtering endpoints and tools
46
+ ### VS Code
45
47
 
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.
48
+ If you use MCP, you can install the MCP server by clicking the link below. You will need to set your environment variables
49
+ in VS Code's `mcp.json`, which can be found via Command Palette > MCP: Open User Configuration.
49
50
 
50
- You can filter by multiple aspects:
51
+ [Open VS Code](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22cas-parser-node-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fcas-parser.stlmcp.com%22%2C%22headers%22%3A%7B%22x-api-key%22%3A%22My%20API%20Key%22%7D%7D)
51
52
 
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
53
+ ### Claude Code
55
54
 
56
- ### Dynamic tools
55
+ If you use Claude Code, you can install the MCP server by running the command below in your terminal. You will need to set your
56
+ environment variables in Claude Code's `.claude.json`, which can be found in your home directory.
57
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
58
  ```
110
-
111
- 2. Exclude specific tools while including others:
112
-
113
- ```bash
114
- --resource=cards --no-tool=create_cards
59
+ claude mcp add cas_parser_node_mcp_api --header "x-api-key: My API Key" --transport http https://cas-parser.stlmcp.com
115
60
  ```
116
61
 
117
- 3. Configure for Cursor client with custom max tool name length:
62
+ ## Code Mode
118
63
 
119
- ```bash
120
- --client=cursor --capability=tool-name-length=40
121
- ```
64
+ This MCP server is built on the "Code Mode" tool scheme. In this MCP Server,
65
+ your agent will write code against the TypeScript SDK, which will then be executed in an
66
+ isolated sandbox. To accomplish this, the server will expose two tools to your agent:
122
67
 
123
- 4. Complex filtering with multiple criteria:
68
+ - The first tool is a docs search tool, which can be used to generically query for
69
+ documentation about your API/SDK.
124
70
 
125
- ```bash
126
- --resource=cards,accounts --operation=read --tag=kyc --no-tool=create_cards
127
- ```
71
+ - The second tool is a code tool, where the agent can write code against the TypeScript SDK.
72
+ The code will be executed in a sandbox environment without web or filesystem access. Then,
73
+ anything the code returns or prints will be returned to the agent as the result of the
74
+ tool call.
75
+
76
+ Using this scheme, agents are capable of performing very complex tasks deterministically
77
+ and repeatably.
128
78
 
129
79
  ## Running remotely
130
80
 
@@ -149,71 +99,3 @@ A configuration JSON for this server might look like this, assuming the server i
149
99
  }
150
100
  }
151
101
  ```
152
-
153
- The command-line arguments for filtering tools and specifying clients can also be used as query parameters in the URL.
154
- For example, to exclude specific tools while including others, use the URL:
155
-
156
- ```
157
- http://localhost:3000?resource=cards&resource=accounts&no_tool=create_cards
158
- ```
159
-
160
- Or, to configure for the Cursor client, with a custom max tool name length, use the URL:
161
-
162
- ```
163
- http://localhost:3000?client=cursor&capability=tool-name-length%3D40
164
- ```
165
-
166
- ## Importing the tools and server individually
167
-
168
- ```js
169
- // Import the server, generated endpoints, or the init function
170
- import { server, endpoints, init } from "cas-parser-node-mcp/server";
171
-
172
- // import a specific tool
173
- import camsKfintechCasParser from "cas-parser-node-mcp/tools/cas-parser/cams-kfintech-cas-parser";
174
-
175
- // initialize the server and all endpoints
176
- init({ server, endpoints });
177
-
178
- // manually start server
179
- const transport = new StdioServerTransport();
180
- await server.connect(transport);
181
-
182
- // or initialize your own server with specific tools
183
- const myServer = new McpServer(...);
184
-
185
- // define your own endpoint
186
- const myCustomEndpoint = {
187
- tool: {
188
- name: 'my_custom_tool',
189
- description: 'My custom tool',
190
- inputSchema: zodToJsonSchema(z.object({ a_property: z.string() })),
191
- },
192
- handler: async (client: client, args: any) => {
193
- return { myResponse: 'Hello world!' };
194
- })
195
- };
196
-
197
- // initialize the server with your custom endpoints
198
- init({ server: myServer, endpoints: [camsKfintechCasParser, myCustomEndpoint] });
199
- ```
200
-
201
- ## Available Tools
202
-
203
- The following tools are available in this MCP server.
204
-
205
- ### Resource `CAS Parser`:
206
-
207
- - `cams_kfintech_cas_parser` (`write`): This endpoint specifically parses CAMS/KFintech CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
208
- Use this endpoint when you know the PDF is from CAMS or KFintech.
209
- - `cdsl_cas_parser` (`write`): This endpoint specifically parses CDSL CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
210
- Use this endpoint when you know the PDF is from CDSL.
211
- - `nsdl_cas_parser` (`write`): This endpoint specifically parses NSDL CAS (Consolidated Account Statement) PDF files and returns data in a unified format.
212
- Use this endpoint when you know the PDF is from NSDL.
213
- - `smart_parse_cas_parser` (`write`): This endpoint parses CAS (Consolidated Account Statement) PDF files from NSDL, CDSL, or CAMS/KFintech and returns data in a unified format.
214
- It auto-detects the CAS type and transforms the data into a consistent structure regardless of the source.
215
-
216
- ### Resource `CAS Generator`:
217
-
218
- - `generate_cas_cas_generator` (`write`): This endpoint generates CAS (Consolidated Account Statement) documents by submitting a mailback request to the specified CAS authority.
219
- Currently only supports KFintech, with plans to support CAMS, CDSL, and NSDL in the future.
package/auth.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ import { IncomingMessage } from 'node:http';
2
+ import { ClientOptions } from 'cas-parser-node';
3
+ export declare const parseAuthHeaders: (req: IncomingMessage, required?: boolean) => Partial<ClientOptions>;
4
+ //# sourceMappingURL=auth.d.mts.map
package/auth.d.mts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.mts","sourceRoot":"","sources":["src/auth.ts"],"names":[],"mappings":"OAEO,EAAE,eAAe,EAAE,MAAM,WAAW;OACpC,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,EAAE,WAAW,OAAO,KAAG,OAAO,CAAC,aAAa,CAIhG,CAAC"}
package/auth.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { IncomingMessage } from 'node:http';
2
+ import { ClientOptions } from 'cas-parser-node';
3
+ export declare const parseAuthHeaders: (req: IncomingMessage, required?: boolean) => Partial<ClientOptions>;
4
+ //# sourceMappingURL=auth.d.ts.map
package/auth.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["src/auth.ts"],"names":[],"mappings":"OAEO,EAAE,eAAe,EAAE,MAAM,WAAW;OACpC,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,EAAE,WAAW,OAAO,KAAG,OAAO,CAAC,aAAa,CAIhG,CAAC"}
@@ -2,9 +2,9 @@
2
2
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.parseAuthHeaders = void 0;
5
- const parseAuthHeaders = (req) => {
5
+ const parseAuthHeaders = (req, required) => {
6
6
  const apiKey = Array.isArray(req.headers['x-api-key']) ? req.headers['x-api-key'][0] : req.headers['x-api-key'];
7
7
  return { apiKey };
8
8
  };
9
9
  exports.parseAuthHeaders = parseAuthHeaders;
10
- //# sourceMappingURL=headers.js.map
10
+ //# sourceMappingURL=auth.js.map
package/auth.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["src/auth.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAK/E,MAAM,gBAAgB,GAAG,CAAC,GAAoB,EAAE,QAAkB,EAA0B,EAAE;IACnG,MAAM,MAAM,GACV,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnG,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
@@ -1,6 +1,6 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
- export const parseAuthHeaders = (req) => {
2
+ export const parseAuthHeaders = (req, required) => {
3
3
  const apiKey = Array.isArray(req.headers['x-api-key']) ? req.headers['x-api-key'][0] : req.headers['x-api-key'];
4
4
  return { apiKey };
5
5
  };
6
- //# sourceMappingURL=headers.mjs.map
6
+ //# sourceMappingURL=auth.mjs.map
package/auth.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.mjs","sourceRoot":"","sources":["src/auth.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAKtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAoB,EAAE,QAAkB,EAA0B,EAAE;IACnG,MAAM,MAAM,GACV,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnG,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC"}
@@ -1,14 +1,14 @@
1
1
  import { ClientOptions } from 'cas-parser-node';
2
2
  export type WorkerInput = {
3
- opts: ClientOptions;
3
+ project_name: string;
4
4
  code: string;
5
+ client_opts: ClientOptions;
6
+ intent?: string | undefined;
5
7
  };
6
- export type WorkerSuccess = {
8
+ export type WorkerOutput = {
9
+ is_error: boolean;
7
10
  result: unknown | null;
8
- logLines: string[];
9
- errLines: string[];
10
- };
11
- export type WorkerError = {
12
- message: string | undefined;
11
+ log_lines: string[];
12
+ err_lines: string[];
13
13
  };
14
14
  //# sourceMappingURL=code-tool-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-types.d.mts","sourceRoot":"","sources":["src/code-tool-types.ts"],"names":[],"mappings":"OAEO,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"code-tool-types.d.mts","sourceRoot":"","sources":["src/code-tool-types.ts"],"names":[],"mappings":"OAEO,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,aAAa,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC"}
@@ -1,14 +1,14 @@
1
1
  import { ClientOptions } from 'cas-parser-node';
2
2
  export type WorkerInput = {
3
- opts: ClientOptions;
3
+ project_name: string;
4
4
  code: string;
5
+ client_opts: ClientOptions;
6
+ intent?: string | undefined;
5
7
  };
6
- export type WorkerSuccess = {
8
+ export type WorkerOutput = {
9
+ is_error: boolean;
7
10
  result: unknown | null;
8
- logLines: string[];
9
- errLines: string[];
10
- };
11
- export type WorkerError = {
12
- message: string | undefined;
11
+ log_lines: string[];
12
+ err_lines: string[];
13
13
  };
14
14
  //# sourceMappingURL=code-tool-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool-types.d.ts","sourceRoot":"","sources":["src/code-tool-types.ts"],"names":[],"mappings":"OAEO,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"code-tool-types.d.ts","sourceRoot":"","sources":["src/code-tool-types.ts"],"names":[],"mappings":"OAEO,EAAE,aAAa,EAAE,MAAM,iBAAiB;AAE/C,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,aAAa,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC"}
package/code-tool.d.mts CHANGED
@@ -1,12 +1,15 @@
1
- import { Endpoint } from "./tools/types.mjs";
1
+ import { McpTool } from "./types.mjs";
2
+ import { SdkMethod } from "./methods.mjs";
2
3
  /**
3
4
  * A tool that runs code against a copy of the SDK.
4
5
  *
5
- * Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
6
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
6
7
  * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
7
8
  * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
8
9
  *
9
10
  * @param endpoints - The endpoints to include in the list.
10
11
  */
11
- export declare function codeTool(): Promise<Endpoint>;
12
+ export declare function codeTool(params: {
13
+ blockedMethods: SdkMethod[] | undefined;
14
+ }): McpTool;
12
15
  //# sourceMappingURL=code-tool.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,EAAE,QAAQ,EAA0B;AAM3C;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CA6HlD"}
1
+ {"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAEO,EAAE,OAAO,EAAgE;OAIzE,EAAE,SAAS,EAAE;AAuBpB;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,cAAc,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CA8FrF"}
package/code-tool.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { Endpoint } from "./tools/types.js";
1
+ import { McpTool } from "./types.js";
2
+ import { SdkMethod } from "./methods.js";
2
3
  /**
3
4
  * A tool that runs code against a copy of the SDK.
4
5
  *
5
- * Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
6
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
6
7
  * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
7
8
  * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
8
9
  *
9
10
  * @param endpoints - The endpoints to include in the list.
10
11
  */
11
- export declare function codeTool(): Promise<Endpoint>;
12
+ export declare function codeTool(params: {
13
+ blockedMethods: SdkMethod[] | undefined;
14
+ }): McpTool;
12
15
  //# sourceMappingURL=code-tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-tool.d.ts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAKO,EAAE,QAAQ,EAA0B;AAM3C;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,CA6HlD"}
1
+ {"version":3,"file":"code-tool.d.ts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAEO,EAAE,OAAO,EAAgE;OAIzE,EAAE,SAAS,EAAE;AAuBpB;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,cAAc,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CA8FrF"}
package/code-tool.js CHANGED
@@ -1,156 +1,110 @@
1
1
  "use strict";
2
2
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.codeTool = codeTool;
38
- const node_path_1 = require("node:path");
39
- const node_url_1 = require("node:url");
5
+ const types_1 = require("./types.js");
6
+ const util_1 = require("./util.js");
7
+ const prompt = `Runs JavaScript code to interact with the Cas Parser API.
8
+
9
+ You are a skilled programmer writing code to interface with the service.
10
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
11
+ For example:
12
+
13
+ \`\`\`
14
+ async function run(client) {
15
+ const response = await client.credits.check();
16
+
17
+ console.log(response.enabled_features);
18
+ }
19
+ \`\`\`
20
+
21
+ You will be returned anything that your function returns, plus the results of any console.log statements.
22
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
23
+ Do not add comments unless necessary for generating better code.
24
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
25
+ Variables will not persist between calls, so make sure to return or log any data you might need later.`;
40
26
  /**
41
27
  * A tool that runs code against a copy of the SDK.
42
28
  *
43
- * Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
29
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
44
30
  * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
45
31
  * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
46
32
  *
47
33
  * @param endpoints - The endpoints to include in the list.
48
34
  */
49
- async function codeTool() {
35
+ function codeTool(params) {
50
36
  const metadata = { resource: 'all', operation: 'write', tags: [] };
51
37
  const tool = {
52
38
  name: 'execute',
53
- description: 'Runs Typescript code to interact with the API.\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client, and it will be run.\nDo not initialize a client, but instead use the client that you are given as a parameter.\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
54
- inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
39
+ description: prompt,
40
+ inputSchema: {
41
+ type: 'object',
42
+ properties: {
43
+ code: {
44
+ type: 'string',
45
+ description: 'Code to execute.',
46
+ },
47
+ intent: {
48
+ type: 'string',
49
+ description: 'Task you are trying to perform. Used for improving the service.',
50
+ },
51
+ },
52
+ required: ['code'],
53
+ },
55
54
  };
56
- // Import dynamically to avoid failing at import time in cases where the environment is not well-supported.
57
- const { newDenoHTTPWorker } = await Promise.resolve().then(() => __importStar(require('@valtown/deno-http-worker')));
58
- const { workerPath } = await Promise.resolve().then(() => __importStar(require('./code-tool-paths.cjs')));
59
55
  const handler = async (client, args) => {
60
- const baseURLHostname = new URL(client.baseURL).hostname;
61
- const { code } = args;
62
- const worker = await newDenoHTTPWorker((0, node_url_1.pathToFileURL)(workerPath), {
63
- runFlags: [
64
- `--node-modules-dir=manual`,
65
- `--allow-read=code-tool-worker.mjs,${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
66
- `--allow-net=${baseURLHostname}`,
67
- // Allow environment variables because instantiating the client will try to read from them,
68
- // even though they are not set.
69
- '--allow-env',
70
- ],
71
- printOutput: true,
72
- spawnOptions: {
73
- cwd: (0, node_path_1.dirname)(workerPath),
74
- },
75
- });
76
- try {
77
- const resp = await new Promise((resolve, reject) => {
78
- worker.addEventListener('exit', (exitCode) => {
79
- reject(new Error(`Worker exited with code ${exitCode}`));
80
- });
81
- const opts = {
82
- baseURL: client.baseURL,
83
- apiKey: client.apiKey,
84
- defaultHeaders: {
85
- 'X-Stainless-MCP': 'true',
86
- },
87
- };
88
- const req = worker.request('http://localhost', {
89
- headers: {
90
- 'content-type': 'application/json',
91
- },
92
- method: 'POST',
93
- }, (resp) => {
94
- const body = [];
95
- resp.on('error', (err) => {
96
- reject(err);
97
- });
98
- resp.on('data', (chunk) => {
99
- body.push(chunk);
100
- });
101
- resp.on('end', () => {
102
- resolve(new Response(Buffer.concat(body).toString(), {
103
- status: resp.statusCode ?? 200,
104
- headers: resp.headers,
105
- }));
106
- });
107
- });
108
- const body = JSON.stringify({
109
- opts,
110
- code,
111
- });
112
- req.write(body, (err) => {
113
- if (err !== null && err !== undefined) {
114
- reject(err);
115
- }
116
- });
117
- req.end();
118
- });
119
- if (resp.status === 200) {
120
- const { result, logLines, errLines } = (await resp.json());
121
- const returnOutput = result === null ? null
122
- : result === undefined ? null
123
- : {
124
- type: 'text',
125
- text: typeof result === 'string' ? result : JSON.stringify(result),
126
- };
127
- const logOutput = logLines.length === 0 ?
128
- null
129
- : {
130
- type: 'text',
131
- text: logLines.join('\n'),
132
- };
133
- const errOutput = errLines.length === 0 ?
134
- null
135
- : {
136
- type: 'text',
137
- text: 'Error output:\n' + errLines.join('\n'),
138
- };
139
- return {
140
- content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
141
- };
142
- }
143
- else {
144
- const { message } = (await resp.json());
145
- throw new Error(message);
56
+ const code = args.code;
57
+ const intent = args.intent;
58
+ // Do very basic blocking of code that includes forbidden method names.
59
+ //
60
+ // WARNING: This is not secure against obfuscation and other evasion methods. If
61
+ // stronger security blocks are required, then these should be enforced in the downstream
62
+ // API (e.g., by having users call the MCP server with API keys with limited permissions).
63
+ if (params.blockedMethods) {
64
+ const blockedMatches = params.blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
65
+ if (blockedMatches.length > 0) {
66
+ return (0, types_1.asErrorResult)(`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
67
+ .map((m) => m.fullyQualifiedName)
68
+ .join(', ')}`);
146
69
  }
147
70
  }
148
- catch (e) {
149
- throw e;
71
+ // this is not required, but passing a Stainless API key for the matching project_name
72
+ // will allow you to run code-mode queries against non-published versions of your SDK.
73
+ const stainlessAPIKey = (0, util_1.readEnv)('STAINLESS_API_KEY');
74
+ const codeModeEndpoint = (0, util_1.readEnv)('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
75
+ const res = await fetch(codeModeEndpoint, {
76
+ method: 'POST',
77
+ headers: {
78
+ ...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
79
+ 'Content-Type': 'application/json',
80
+ client_envs: JSON.stringify({
81
+ CAS_PARSER_API_KEY: (0, util_1.requireValue)((0, util_1.readEnv)('CAS_PARSER_API_KEY') ?? client.apiKey, 'set CAS_PARSER_API_KEY environment variable or provide apiKey client option'),
82
+ CAS_PARSER_BASE_URL: (0, util_1.readEnv)('CAS_PARSER_BASE_URL') ?? (0, util_1.readEnv)('CAS_PARSER_ENVIRONMENT') ?
83
+ undefined
84
+ : client.baseURL ?? undefined,
85
+ }),
86
+ },
87
+ body: JSON.stringify({
88
+ project_name: 'cas-parser',
89
+ code,
90
+ intent,
91
+ client_opts: { environment: ((0, util_1.readEnv)('CAS_PARSER_ENVIRONMENT') || undefined) },
92
+ }),
93
+ });
94
+ if (!res.ok) {
95
+ throw new Error(`${res.status}: ${res.statusText} error when trying to contact Code Tool server. Details: ${await res.text()}`);
150
96
  }
151
- finally {
152
- worker.terminate();
97
+ const { is_error, result, log_lines, err_lines } = (await res.json());
98
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
99
+ const output = {
100
+ result,
101
+ ...(log_lines.length > 0 && { log_lines }),
102
+ ...(err_lines.length > 0 && { err_lines }),
103
+ };
104
+ if (is_error) {
105
+ return (0, types_1.asErrorResult)(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
153
106
  }
107
+ return (0, types_1.asTextContentResult)(output);
154
108
  };
155
109
  return { metadata, tool, handler };
156
110
  }