@@ -38,7 +38,7 @@ For clients with a configuration JSON, it might look something like this:
3838 "mcpServers" : {
3939 "stainless_api_sdk_api" : {
4040 "command" : " npx" ,
41- "args" : [" -y" , " @stainless-api/sdk-mcp" , " --client=claude " , " --tools=all " ],
41+ "args" : [" -y" , " @stainless-api/sdk-mcp" ],
4242 "env" : {
4343 "STAINLESS_API_KEY" : " My API Key" ,
4444 "STAINLESS_PROJECT" : " example-project" ,
@@ -72,110 +72,22 @@ environment variables in Claude Code's `.claude.json`, which can be found in you
7272claude mcp add --transport stdio stainless_api_sdk_api --env STAINLESS_API_KEY="Your STAINLESS_API_KEY here." STAINLESS_PROJECT="Your STAINLESS_PROJECT here." -- npx -y @stainless-api/sdk-mcp
7373```
7474
75- ## Exposing endpoints to your MCP Client
75+ ## Code Mode
7676
77- There are three ways to expose endpoints as tools in the MCP server:
77+ This MCP server is built on the "Code Mode" tool scheme. In this MCP Server,
78+ your agent will write code against the TypeScript SDK, which will then be executed in an
79+ isolated sandbox. To accomplish this, the server will expose two tools to your agent:
7880
79- 1 . Exposing one tool per endpoint, and filtering as necessary
80- 2 . Exposing a set of tools to dynamically discover and invoke endpoints from the API
81- 3 . Exposing a docs search tool and a code execution tool, allowing the client to write code to be executed against the TypeScript client
81+ - The first tool is a docs search tool, which can be used to generically query for
82+ documentation about your API/SDK.
8283
83- ### Filtering endpoints and tools
84+ - The second tool is a code tool, where the agent can write code against the TypeScript SDK.
85+ The code will be executed in a sandbox environment without web or filesystem access. Then,
86+ anything the code returns or prints will be returned to the agent as the result of the
87+ tool call.
8488
85- You can run the package on the command line to discover and filter the set of tools that are exposed by the
86- MCP Server. This can be helpful for large APIs where including all endpoints at once is too much for your AI's
87- context window.
88-
89- You can filter by multiple aspects:
90-
91- - ` --tool ` includes a specific tool by name
92- - ` --resource ` includes all tools under a specific resource, and can have wildcards, e.g. ` my.resource* `
93- - ` --operation ` includes just read (get/list) or just write operations
94-
95- ### Dynamic tools
96-
97- If you specify ` --tools=dynamic ` to the MCP server, instead of exposing one tool per endpoint in the API, it will
98- expose the following tools:
99-
100- 1 . ` list_api_endpoints ` - Discovers available endpoints, with optional filtering by search query
101- 2 . ` get_api_endpoint_schema ` - Gets detailed schema information for a specific endpoint
102- 3 . ` invoke_api_endpoint ` - Executes any endpoint with the appropriate parameters
103-
104- This allows you to have the full set of API endpoints available to your MCP Client, while not requiring that all
105- of their schemas be loaded into context at once. Instead, the LLM will automatically use these tools together to
106- search for, look up, and invoke endpoints dynamically. However, due to the indirect nature of the schemas, it
107- can struggle to provide the correct properties a bit more than when tools are imported explicitly. Therefore,
108- you can opt-in to explicit tools, the dynamic tools, or both.
109-
110- See more information with ` --help ` .
111-
112- All of these command-line options can be repeated, combined together, and have corresponding exclusion versions (e.g. ` --no-tool ` ).
113-
114- Use ` --list ` to see the list of available tools, or see below.
115-
116- ### Code execution
117-
118- If you specify ` --tools=code ` to the MCP server, it will expose just two tools:
119-
120- - ` search_docs ` - Searches the API documentation and returns a list of markdown results
121- - ` execute ` - Runs code against the TypeScript client
122-
123- This allows the LLM to implement more complex logic by chaining together many API calls without loading
124- intermediary results into its context window.
125-
126- The code execution itself happens in a Deno sandbox that has network access only to the base URL for the API.
127-
128- ### Specifying the MCP Client
129-
130- Different clients have varying abilities to handle arbitrary tools and schemas.
131-
132- You can specify the client you are using with the ` --client ` argument, and the MCP server will automatically
133- serve tools and schemas that are more compatible with that client.
134-
135- - ` --client=<type> ` : Set all capabilities based on a known MCP client
136-
137- - Valid values: ` openai-agents ` , ` claude ` , ` claude-code ` , ` cursor `
138- - Example: ` --client=cursor `
139-
140- Additionally, if you have a client not on the above list, or the client has gotten better
141- over time, you can manually enable or disable certain capabilities:
142-
143- - ` --capability=<name> ` : Specify individual client capabilities
144- - Available capabilities:
145- - ` top-level-unions ` : Enable support for top-level unions in tool schemas
146- - ` valid-json ` : Enable JSON string parsing for arguments
147- - ` refs ` : Enable support for $ref pointers in schemas
148- - ` unions ` : Enable support for union types (anyOf) in schemas
149- - ` formats ` : Enable support for format validations in schemas (e.g. date-time, email)
150- - ` tool-name-length=N ` : Set maximum tool name length to N characters
151- - Example: ` --capability=top-level-unions --capability=tool-name-length=40 `
152- - Example: ` --capability=top-level-unions,tool-name-length=40 `
153-
154- ### Examples
155-
156- 1 . Filter for read operations on cards:
157-
158- ``` bash
159- --resource=cards --operation=read
160- ```
161-
162- 2 . Exclude specific tools while including others:
163-
164- ``` bash
165- --resource=cards --no-tool=create_cards
166- ```
167-
168- 3 . Configure for Cursor client with custom max tool name length:
169-
170- ``` bash
171- --client=cursor --capability=tool-name-length=40
172- ```
173-
174- 4 . Complex filtering with multiple criteria:
175-
176- ``` bash
177- --resource=cards,accounts --operation=read --tag=kyc --no-tool=create_cards
178- ```
89+ Using this scheme, agents are capable of performing very complex tasks deterministically
90+ and repeatably.
17991
18092## Running remotely
18193
@@ -202,127 +114,3 @@ A configuration JSON for this server might look like this, assuming the server i
202114 }
203115}
204116```
205-
206- The command-line arguments for filtering tools and specifying clients can also be used as query parameters in the URL.
207- For example, to exclude specific tools while including others, use the URL:
208-
209- ```
210- http://localhost:3000?resource=cards&resource=accounts&no_tool=create_cards
211- ```
212-
213- Or, to configure for the Cursor client, with a custom max tool name length, use the URL:
214-
215- ```
216- http://localhost:3000?client=cursor&capability=tool-name-length%3D40
217- ```
218-
219- ## Importing the tools and server individually
220-
221- ``` js
222- // Import the server, generated endpoints, or the init function
223- import { server , endpoints , init } from " @stainless-api/sdk-mcp/server" ;
224-
225- // import a specific tool
226- import createProjects from " @stainless-api/sdk-mcp/tools/projects/create-projects" ;
227-
228- // initialize the server and all endpoints
229- init ({ server, endpoints });
230-
231- // manually start server
232- const transport = new StdioServerTransport ();
233- await server .connect (transport);
234-
235- // or initialize your own server with specific tools
236- const myServer = new McpServer (... );
237-
238- // define your own endpoint
239- const myCustomEndpoint = {
240- tool: {
241- name: ' my_custom_tool' ,
242- description: ' My custom tool' ,
243- inputSchema: zodToJsonSchema (z .object ({ a_property: z .string () })),
244- },
245- handler: async (client : client , args : any ) => {
246- return { myResponse: ' Hello world!' };
247- })
248- };
249-
250- // initialize the server with your custom endpoints
251- init ({ server: myServer, endpoints: [createProjects, myCustomEndpoint] });
252- ```
253-
254- ## Available Tools
255-
256- The following tools are available in this MCP server.
257-
258- ### Resource ` projects ` :
259-
260- - ` create_projects ` (` write ` ): Create a new project.
261- - ` retrieve_projects ` (` read ` ): Retrieve a project by name.
262- - ` update_projects ` (` write ` ): Update a project's properties.
263- - ` list_projects ` (` read ` ): List projects in an organization, from oldest to newest.
264-
265- ### Resource ` projects.branches ` :
266-
267- - ` create_projects_branches ` (` write ` ): Create a new branch for a project.
268-
269- The branch inherits the config files from the revision pointed to by the
270- ` branch_from ` parameter. In addition, if the revision is a branch name,
271- the branch will also inherit custom code changes from that branch.
272-
273- - ` retrieve_projects_branches ` (` read ` ): Retrieve a project branch by name.
274- - ` list_projects_branches ` (` read ` ): Retrieve a project branch by name.
275- - ` delete_projects_branches ` (` write ` ): Delete a project branch by name.
276- - ` rebase_projects_branches ` (` write ` ): Rebase a project branch.
277-
278- The branch is rebased onto the ` base ` branch or commit SHA, inheriting
279- any config and custom code changes.
280-
281- - ` reset_projects_branches ` (` write ` ): Reset a project branch.
282-
283- If ` branch ` === ` main ` , the branch is reset to ` target_config_sha ` . Otherwise, the
284- branch is reset to ` main ` .
285-
286- ### Resource ` projects.configs ` :
287-
288- - ` retrieve_projects_configs ` (` read ` ):
289- Retrieve the configuration files for a given project.
290- - ` guess_projects_configs ` (` write ` ):
291- Generate suggestions for changes to config files based on an OpenAPI spec.
292-
293- ### Resource ` builds ` :
294-
295- - ` create_builds ` (` write ` ): Create a build, on top of a project branch, against a given input revision.
296-
297- The project branch will be modified so that its latest set of config files
298- points to the one specified by the input revision.
299-
300- - ` retrieve_builds ` (` read ` ): Retrieve a build by its ID.
301- - ` list_builds ` (` read ` ): List user-triggered builds for a given project.
302-
303- An optional revision can be specified to filter by config commit SHA, or
304- hashes of file contents.
305-
306- ### Resource ` builds.diagnostics ` :
307-
308- - ` list_builds_diagnostics ` (` read ` ): Get the list of diagnostics for a given build.
309-
310- If no language targets are specified, diagnostics for all languages are returned.
311-
312- ### Resource ` builds.target_outputs ` :
313-
314- - ` retrieve_builds_target_outputs ` (` read ` ): Retrieve a method to download an output for a given build target.
315-
316- If the requested type of output is ` source ` , and the requested output
317- method is ` url ` , a download link to a tarball of the source files is
318- returned. If the requested output method is ` git ` , a Git remote, ref,
319- and access token (if necessary) is returned.
320-
321- Otherwise, the possible types of outputs are specific to the requested
322- target, and the output method _ must_ be ` url ` . See the documentation for
323- ` type ` for more information.
324-
325- ### Resource ` orgs ` :
326-
327- - ` retrieve_orgs ` (` read ` ): Retrieve an organization by name.
328- - ` list_orgs ` (` read ` ): List organizations accessible to the current authentication method.
0 commit comments