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.
- package/LICENSE +1 -1
- package/README.md +29 -147
- package/auth.d.mts +4 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +4 -0
- package/auth.d.ts.map +1 -0
- package/{headers.js → auth.js} +2 -2
- package/auth.js.map +1 -0
- package/{headers.mjs → auth.mjs} +2 -2
- package/auth.mjs.map +1 -0
- package/code-tool-types.d.mts +7 -7
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts +7 -7
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool.d.mts +6 -3
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +6 -3
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +86 -132
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +86 -99
- package/code-tool.mjs.map +1 -1
- package/{tools/cas-generator/generate-cas-cas-generator.d.ts → docs-search-tool.d.mts} +17 -11
- package/docs-search-tool.d.mts.map +1 -0
- package/{tools/cas-generator/generate-cas-cas-generator.d.mts → docs-search-tool.d.ts} +17 -11
- package/docs-search-tool.d.ts.map +1 -0
- package/docs-search-tool.js +57 -0
- package/docs-search-tool.js.map +1 -0
- package/docs-search-tool.mjs +53 -0
- package/docs-search-tool.mjs.map +1 -0
- package/http.d.mts +9 -4
- package/http.d.mts.map +1 -1
- package/http.d.ts +9 -4
- package/http.d.ts.map +1 -1
- package/http.js +31 -34
- package/http.js.map +1 -1
- package/http.mjs +31 -34
- package/http.mjs.map +1 -1
- package/index.js +8 -40
- package/index.js.map +1 -1
- package/index.mjs +8 -40
- package/index.mjs.map +1 -1
- package/methods.d.mts +10 -0
- package/methods.d.mts.map +1 -0
- package/methods.d.ts +10 -0
- package/methods.d.ts.map +1 -0
- package/methods.js +167 -0
- package/methods.js.map +1 -0
- package/methods.mjs +163 -0
- package/methods.mjs.map +1 -0
- package/options.d.mts +5 -9
- package/options.d.mts.map +1 -1
- package/options.d.ts +5 -9
- package/options.d.ts.map +1 -1
- package/options.js +37 -362
- package/options.js.map +1 -1
- package/options.mjs +37 -362
- package/options.mjs.map +1 -1
- package/package.json +57 -79
- package/server.d.mts +5 -15
- package/server.d.mts.map +1 -1
- package/server.d.ts +5 -15
- package/server.d.ts.map +1 -1
- package/server.js +54 -87
- package/server.js.map +1 -1
- package/server.mjs +53 -82
- package/server.mjs.map +1 -1
- package/src/{headers.ts → auth.ts} +1 -1
- package/src/code-tool-types.ts +7 -5
- package/src/code-tool.ts +104 -117
- package/src/docs-search-tool.ts +65 -0
- package/src/http.ts +44 -40
- package/src/index.ts +9 -52
- package/src/methods.ts +188 -0
- package/src/options.ts +48 -384
- package/src/server.ts +63 -97
- package/src/stdio.ts +4 -4
- package/src/{tools/types.ts → types.ts} +13 -1
- package/src/util.ts +25 -0
- package/stdio.d.mts +1 -1
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +1 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +3 -3
- package/stdio.js.map +1 -1
- package/stdio.mjs +3 -3
- package/stdio.mjs.map +1 -1
- package/{tools/types.d.mts → types.d.mts} +2 -1
- package/types.d.mts.map +1 -0
- package/{tools/types.d.ts → types.d.ts} +2 -1
- package/types.d.ts.map +1 -0
- package/{tools/types.js → types.js} +12 -0
- package/types.js.map +1 -0
- package/{tools/types.mjs → types.mjs} +11 -0
- package/types.mjs.map +1 -0
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
- package/code-tool-paths.cjs +0 -6
- package/code-tool-paths.cjs.map +0 -1
- package/code-tool-paths.d.cts +0 -2
- package/code-tool-paths.d.cts.map +0 -1
- package/code-tool-worker.d.mts +0 -5
- package/code-tool-worker.d.mts.map +0 -1
- package/code-tool-worker.d.ts +0 -5
- package/code-tool-worker.d.ts.map +0 -1
- package/code-tool-worker.js +0 -45
- package/code-tool-worker.js.map +0 -1
- package/code-tool-worker.mjs +0 -40
- package/code-tool-worker.mjs.map +0 -1
- package/compat.d.mts +0 -58
- package/compat.d.mts.map +0 -1
- package/compat.d.ts +0 -58
- package/compat.d.ts.map +0 -1
- package/compat.js +0 -387
- package/compat.js.map +0 -1
- package/compat.mjs +0 -378
- package/compat.mjs.map +0 -1
- package/dynamic-tools.d.mts +0 -12
- package/dynamic-tools.d.mts.map +0 -1
- package/dynamic-tools.d.ts +0 -12
- package/dynamic-tools.d.ts.map +0 -1
- package/dynamic-tools.js +0 -135
- package/dynamic-tools.js.map +0 -1
- package/dynamic-tools.mjs +0 -132
- package/dynamic-tools.mjs.map +0 -1
- package/filtering.d.mts +0 -2
- package/filtering.d.mts.map +0 -1
- package/filtering.d.ts +0 -2
- package/filtering.d.ts.map +0 -1
- package/filtering.js +0 -20
- package/filtering.js.map +0 -1
- package/filtering.mjs +0 -13
- package/filtering.mjs.map +0 -1
- package/headers.d.mts +0 -4
- package/headers.d.mts.map +0 -1
- package/headers.d.ts +0 -4
- package/headers.d.ts.map +0 -1
- package/headers.js.map +0 -1
- package/headers.mjs.map +0 -1
- package/src/code-tool-paths.cts +0 -3
- package/src/code-tool-worker.ts +0 -46
- package/src/compat.ts +0 -483
- package/src/dynamic-tools.ts +0 -159
- package/src/filtering.ts +0 -14
- package/src/tools/cas-generator/generate-cas-cas-generator.ts +0 -67
- package/src/tools/cas-parser/cams-kfintech-cas-parser.ts +0 -47
- package/src/tools/cas-parser/cdsl-cas-parser.ts +0 -47
- package/src/tools/cas-parser/nsdl-cas-parser.ts +0 -47
- package/src/tools/cas-parser/smart-parse-cas-parser.ts +0 -47
- package/src/tools/index.ts +0 -79
- package/src/tools.ts +0 -1
- package/tools/cas-generator/generate-cas-cas-generator.d.mts.map +0 -1
- package/tools/cas-generator/generate-cas-cas-generator.d.ts.map +0 -1
- package/tools/cas-generator/generate-cas-cas-generator.js +0 -62
- package/tools/cas-generator/generate-cas-cas-generator.js.map +0 -1
- package/tools/cas-generator/generate-cas-cas-generator.mjs +0 -58
- package/tools/cas-generator/generate-cas-cas-generator.mjs.map +0 -1
- package/tools/cas-parser/cams-kfintech-cas-parser.d.mts +0 -45
- package/tools/cas-parser/cams-kfintech-cas-parser.d.mts.map +0 -1
- package/tools/cas-parser/cams-kfintech-cas-parser.d.ts +0 -45
- package/tools/cas-parser/cams-kfintech-cas-parser.d.ts.map +0 -1
- package/tools/cas-parser/cams-kfintech-cas-parser.js +0 -43
- package/tools/cas-parser/cams-kfintech-cas-parser.js.map +0 -1
- package/tools/cas-parser/cams-kfintech-cas-parser.mjs +0 -39
- package/tools/cas-parser/cams-kfintech-cas-parser.mjs.map +0 -1
- package/tools/cas-parser/cdsl-cas-parser.d.mts +0 -45
- package/tools/cas-parser/cdsl-cas-parser.d.mts.map +0 -1
- package/tools/cas-parser/cdsl-cas-parser.d.ts +0 -45
- package/tools/cas-parser/cdsl-cas-parser.d.ts.map +0 -1
- package/tools/cas-parser/cdsl-cas-parser.js +0 -43
- package/tools/cas-parser/cdsl-cas-parser.js.map +0 -1
- package/tools/cas-parser/cdsl-cas-parser.mjs +0 -39
- package/tools/cas-parser/cdsl-cas-parser.mjs.map +0 -1
- package/tools/cas-parser/nsdl-cas-parser.d.mts +0 -45
- package/tools/cas-parser/nsdl-cas-parser.d.mts.map +0 -1
- package/tools/cas-parser/nsdl-cas-parser.d.ts +0 -45
- package/tools/cas-parser/nsdl-cas-parser.d.ts.map +0 -1
- package/tools/cas-parser/nsdl-cas-parser.js +0 -43
- package/tools/cas-parser/nsdl-cas-parser.js.map +0 -1
- package/tools/cas-parser/nsdl-cas-parser.mjs +0 -39
- package/tools/cas-parser/nsdl-cas-parser.mjs.map +0 -1
- package/tools/cas-parser/smart-parse-cas-parser.d.mts +0 -45
- package/tools/cas-parser/smart-parse-cas-parser.d.mts.map +0 -1
- package/tools/cas-parser/smart-parse-cas-parser.d.ts +0 -45
- package/tools/cas-parser/smart-parse-cas-parser.d.ts.map +0 -1
- package/tools/cas-parser/smart-parse-cas-parser.js +0 -43
- package/tools/cas-parser/smart-parse-cas-parser.js.map +0 -1
- package/tools/cas-parser/smart-parse-cas-parser.mjs +0 -39
- package/tools/cas-parser/smart-parse-cas-parser.mjs.map +0 -1
- package/tools/index.d.mts +0 -10
- package/tools/index.d.mts.map +0 -1
- package/tools/index.d.ts +0 -10
- package/tools/index.d.ts.map +0 -1
- package/tools/index.js +0 -63
- package/tools/index.js.map +0 -1
- package/tools/index.mjs +0 -56
- package/tools/index.mjs.map +0 -1
- package/tools/types.d.mts.map +0 -1
- package/tools/types.d.ts.map +0 -1
- package/tools/types.js.map +0 -1
- package/tools/types.mjs.map +0 -1
- package/tools.d.mts +0 -2
- package/tools.d.mts.map +0 -1
- package/tools.d.ts +0 -2
- package/tools.d.ts.map +0 -1
- package/tools.js +0 -18
- package/tools.js.map +0 -1
- package/tools.mjs +0 -2
- 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
|
|
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"
|
|
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
|
-
|
|
39
|
+
### Cursor
|
|
38
40
|
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
2. Exposing a set of tools to dynamically discover and invoke endpoints from the API
|
|
44
|
+
[](https://cursor.com/en-US/install-mcp?name=cas-parser-node-mcp&config=eyJuYW1lIjoiY2FzLXBhcnNlci1ub2RlLW1jcCIsInRyYW5zcG9ydCI6Imh0dHAiLCJ1cmwiOiJodHRwczovL2Nhcy1wYXJzZXIuc3RsbWNwLmNvbSIsImhlYWRlcnMiOnsieC1hcGkta2V5IjoiTXkgQVBJIEtleSJ9fQ)
|
|
43
45
|
|
|
44
|
-
###
|
|
46
|
+
### VS Code
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
+
## Code Mode
|
|
118
63
|
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
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
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"}
|
package/{headers.js → auth.js}
RENAMED
|
@@ -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=
|
|
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"}
|
package/{headers.mjs → auth.mjs}
RENAMED
|
@@ -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=
|
|
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"}
|
package/code-tool-types.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ClientOptions } from 'cas-parser-node';
|
|
2
2
|
export type WorkerInput = {
|
|
3
|
-
|
|
3
|
+
project_name: string;
|
|
4
4
|
code: string;
|
|
5
|
+
client_opts: ClientOptions;
|
|
6
|
+
intent?: string | undefined;
|
|
5
7
|
};
|
|
6
|
-
export type
|
|
8
|
+
export type WorkerOutput = {
|
|
9
|
+
is_error: boolean;
|
|
7
10
|
result: unknown | null;
|
|
8
|
-
|
|
9
|
-
|
|
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,
|
|
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"}
|
package/code-tool-types.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ClientOptions } from 'cas-parser-node';
|
|
2
2
|
export type WorkerInput = {
|
|
3
|
-
|
|
3
|
+
project_name: string;
|
|
4
4
|
code: string;
|
|
5
|
+
client_opts: ClientOptions;
|
|
6
|
+
intent?: string | undefined;
|
|
5
7
|
};
|
|
6
|
-
export type
|
|
8
|
+
export type WorkerOutput = {
|
|
9
|
+
is_error: boolean;
|
|
7
10
|
result: unknown | null;
|
|
8
|
-
|
|
9
|
-
|
|
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
|
package/code-tool-types.d.ts.map
CHANGED
|
@@ -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,
|
|
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 {
|
|
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
|
|
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(
|
|
12
|
+
export declare function codeTool(params: {
|
|
13
|
+
blockedMethods: SdkMethod[] | undefined;
|
|
14
|
+
}): McpTool;
|
|
12
15
|
//# sourceMappingURL=code-tool.d.mts.map
|
package/code-tool.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"
|
|
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 {
|
|
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
|
|
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(
|
|
12
|
+
export declare function codeTool(params: {
|
|
13
|
+
blockedMethods: SdkMethod[] | undefined;
|
|
14
|
+
}): McpTool;
|
|
12
15
|
//# sourceMappingURL=code-tool.d.ts.map
|
package/code-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-tool.d.ts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"
|
|
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
|
|
39
|
-
const
|
|
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
|
|
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
|
-
|
|
35
|
+
function codeTool(params) {
|
|
50
36
|
const metadata = { resource: 'all', operation: 'write', tags: [] };
|
|
51
37
|
const tool = {
|
|
52
38
|
name: 'execute',
|
|
53
|
-
description:
|
|
54
|
-
inputSchema: {
|
|
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
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
149
|
-
|
|
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
|
-
|
|
152
|
-
|
|
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
|
}
|