@zavudev/sdk-mcp 0.27.0 → 0.29.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.
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +19 -3
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +19 -3
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +1 -1
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +1 -1
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +22 -3
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +22 -3
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts +2 -4
- package/http.d.mts.map +1 -1
- package/http.d.ts +2 -4
- package/http.d.ts.map +1 -1
- package/http.js +52 -19
- package/http.js.map +1 -1
- package/http.mjs +52 -19
- package/http.mjs.map +1 -1
- package/index.js +12 -11
- package/index.js.map +1 -1
- package/index.mjs +12 -11
- package/index.mjs.map +1 -1
- package/instructions.d.mts.map +1 -1
- package/instructions.d.ts.map +1 -1
- package/instructions.js +4 -13
- package/instructions.js.map +1 -1
- package/instructions.mjs +4 -13
- package/instructions.mjs.map +1 -1
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/options.d.mts +1 -0
- package/options.d.mts.map +1 -1
- package/options.d.ts +1 -0
- package/options.d.ts.map +1 -1
- package/options.js +9 -0
- package/options.js.map +1 -1
- package/options.mjs +9 -0
- package/options.mjs.map +1 -1
- package/package.json +21 -7
- package/server.js +1 -1
- package/server.mjs +1 -1
- package/src/code-tool.ts +27 -3
- package/src/docs-search-tool.ts +36 -4
- package/src/http.ts +53 -21
- package/src/index.ts +14 -12
- package/src/instructions.ts +4 -13
- package/src/logger.ts +28 -0
- package/src/options.ts +11 -0
- package/src/server.ts +1 -1
- package/src/stdio.ts +2 -1
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +2 -1
- package/stdio.js.map +1 -1
- package/stdio.mjs +2 -1
- package/stdio.mjs.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zavudev/sdk-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "The official MCP Server for the Zavudev API",
|
|
5
5
|
"author": "Zavudev <hi@zavu.dev>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -18,17 +18,21 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@zavudev/sdk": "^0.
|
|
21
|
+
"@zavudev/sdk": "^0.29.0",
|
|
22
|
+
"ajv": "^8.18.0",
|
|
22
23
|
"@cloudflare/cabidela": "^0.2.4",
|
|
23
|
-
"@
|
|
24
|
+
"@hono/node-server": "^1.19.10",
|
|
25
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
26
|
+
"hono": "^4.12.4",
|
|
24
27
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
25
28
|
"cookie-parser": "^1.4.6",
|
|
26
29
|
"cors": "^2.8.5",
|
|
27
30
|
"express": "^5.1.0",
|
|
28
31
|
"fuse.js": "^7.1.0",
|
|
29
32
|
"jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
33
|
+
"pino": "^10.3.1",
|
|
34
|
+
"pino-http": "^11.0.0",
|
|
35
|
+
"pino-pretty": "^13.1.3",
|
|
32
36
|
"qs": "^6.14.1",
|
|
33
37
|
"typescript": "5.8.3",
|
|
34
38
|
"yargs": "^17.7.2",
|
|
@@ -138,6 +142,16 @@
|
|
|
138
142
|
"./instructions.mjs": {
|
|
139
143
|
"default": "./instructions.mjs"
|
|
140
144
|
},
|
|
145
|
+
"./logger": {
|
|
146
|
+
"import": "./logger.mjs",
|
|
147
|
+
"require": "./logger.js"
|
|
148
|
+
},
|
|
149
|
+
"./logger.js": {
|
|
150
|
+
"default": "./logger.js"
|
|
151
|
+
},
|
|
152
|
+
"./logger.mjs": {
|
|
153
|
+
"default": "./logger.mjs"
|
|
154
|
+
},
|
|
141
155
|
"./methods": {
|
|
142
156
|
"import": "./methods.mjs",
|
|
143
157
|
"require": "./methods.js"
|
|
@@ -204,7 +218,7 @@
|
|
|
204
218
|
"build": "bash ./build",
|
|
205
219
|
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
206
220
|
"tsn": "ts-node -r tsconfig-paths/register",
|
|
207
|
-
"lint": "eslint
|
|
208
|
-
"fix": "eslint --fix
|
|
221
|
+
"lint": "eslint .",
|
|
222
|
+
"fix": "eslint --fix ."
|
|
209
223
|
}
|
|
210
224
|
}
|
package/server.js
CHANGED
|
@@ -17,7 +17,7 @@ const instructions_1 = require("./instructions.js");
|
|
|
17
17
|
const methods_1 = require("./methods.js");
|
|
18
18
|
const newMcpServer = async (stainlessApiKey) => new mcp_js_1.McpServer({
|
|
19
19
|
name: 'zavudev_sdk_api',
|
|
20
|
-
version: '0.
|
|
20
|
+
version: '0.29.0',
|
|
21
21
|
}, {
|
|
22
22
|
instructions: await (0, instructions_1.getInstructions)(stainlessApiKey),
|
|
23
23
|
capabilities: { tools: {}, logging: {} },
|
package/server.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { getInstructions } from "./instructions.mjs";
|
|
|
8
8
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
9
9
|
export const newMcpServer = async (stainlessApiKey) => new McpServer({
|
|
10
10
|
name: 'zavudev_sdk_api',
|
|
11
|
-
version: '0.
|
|
11
|
+
version: '0.29.0',
|
|
12
12
|
}, {
|
|
13
13
|
instructions: await getInstructions(stainlessApiKey),
|
|
14
14
|
capabilities: { tools: {}, logging: {} },
|
package/src/code-tool.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
18
18
|
import { readEnv, requireValue } from './util';
|
|
19
19
|
import { WorkerInput, WorkerOutput } from './code-tool-types';
|
|
20
|
+
import { getLogger } from './logger';
|
|
20
21
|
import { SdkMethod } from './methods';
|
|
21
22
|
import { McpCodeExecutionMode } from './options';
|
|
22
23
|
import { ClientOptions } from '@zavudev/sdk';
|
|
@@ -83,6 +84,8 @@ export function codeTool({
|
|
|
83
84
|
},
|
|
84
85
|
};
|
|
85
86
|
|
|
87
|
+
const logger = getLogger();
|
|
88
|
+
|
|
86
89
|
const handler = async ({
|
|
87
90
|
reqContext,
|
|
88
91
|
args,
|
|
@@ -107,11 +110,27 @@ export function codeTool({
|
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
let result: ToolCallResult;
|
|
114
|
+
const startTime = Date.now();
|
|
115
|
+
|
|
110
116
|
if (codeExecutionMode === 'local') {
|
|
111
|
-
|
|
117
|
+
logger.debug('Executing code in local Deno environment');
|
|
118
|
+
result = await localDenoHandler({ reqContext, args });
|
|
112
119
|
} else {
|
|
113
|
-
|
|
120
|
+
logger.debug('Executing code in remote Stainless environment');
|
|
121
|
+
result = await remoteStainlessHandler({ reqContext, args });
|
|
114
122
|
}
|
|
123
|
+
|
|
124
|
+
logger.info(
|
|
125
|
+
{
|
|
126
|
+
codeExecutionMode,
|
|
127
|
+
durationMs: Date.now() - startTime,
|
|
128
|
+
isError: result.isError,
|
|
129
|
+
contentRows: result.content?.length ?? 0,
|
|
130
|
+
},
|
|
131
|
+
'Got code tool execution result',
|
|
132
|
+
);
|
|
133
|
+
return result;
|
|
115
134
|
};
|
|
116
135
|
|
|
117
136
|
return { metadata, tool, handler };
|
|
@@ -136,7 +155,7 @@ const remoteStainlessHandler = async ({
|
|
|
136
155
|
headers: {
|
|
137
156
|
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
|
|
138
157
|
'Content-Type': 'application/json',
|
|
139
|
-
|
|
158
|
+
'x-stainless-mcp-client-envs': JSON.stringify({
|
|
140
159
|
ZAVUDEV_API_KEY: requireValue(
|
|
141
160
|
readEnv('ZAVUDEV_API_KEY') ?? client.apiKey,
|
|
142
161
|
'set ZAVUDEV_API_KEY environment variable or provide apiKey client option',
|
|
@@ -153,6 +172,11 @@ const remoteStainlessHandler = async ({
|
|
|
153
172
|
});
|
|
154
173
|
|
|
155
174
|
if (!res.ok) {
|
|
175
|
+
if (res.status === 404 && !reqContext.stainlessApiKey) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
'Could not access code tool for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
|
|
178
|
+
);
|
|
179
|
+
}
|
|
156
180
|
throw new Error(
|
|
157
181
|
`${res.status}: ${
|
|
158
182
|
res.statusText
|
package/src/docs-search-tool.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { Metadata, McpRequestContext, asTextContentResult } from './types';
|
|
4
3
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { Metadata, McpRequestContext, asTextContentResult } from './types';
|
|
5
|
+
import { getLogger } from './logger';
|
|
5
6
|
|
|
6
7
|
export const metadata: Metadata = {
|
|
7
8
|
resource: 'all',
|
|
@@ -12,7 +13,8 @@ export const metadata: Metadata = {
|
|
|
12
13
|
|
|
13
14
|
export const tool: Tool = {
|
|
14
15
|
name: 'search_docs',
|
|
15
|
-
description:
|
|
16
|
+
description:
|
|
17
|
+
'Search SDK documentation to find methods, parameters, and usage examples for interacting with the API. Use this before writing code when you need to discover the right approach.',
|
|
16
18
|
inputSchema: {
|
|
17
19
|
type: 'object',
|
|
18
20
|
properties: {
|
|
@@ -50,19 +52,49 @@ export const handler = async ({
|
|
|
50
52
|
}) => {
|
|
51
53
|
const body = args as any;
|
|
52
54
|
const query = new URLSearchParams(body).toString();
|
|
55
|
+
|
|
56
|
+
const startTime = Date.now();
|
|
53
57
|
const result = await fetch(`${docsSearchURL}?${query}`, {
|
|
54
58
|
headers: {
|
|
55
59
|
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
|
|
56
60
|
},
|
|
57
61
|
});
|
|
58
62
|
|
|
63
|
+
const logger = getLogger();
|
|
64
|
+
|
|
59
65
|
if (!result.ok) {
|
|
66
|
+
const errorText = await result.text();
|
|
67
|
+
logger.warn(
|
|
68
|
+
{
|
|
69
|
+
durationMs: Date.now() - startTime,
|
|
70
|
+
query: body.query,
|
|
71
|
+
status: result.status,
|
|
72
|
+
statusText: result.statusText,
|
|
73
|
+
errorText,
|
|
74
|
+
},
|
|
75
|
+
'Got error response from docs search tool',
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if (result.status === 404 && !reqContext.stainlessApiKey) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'Could not find docs for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
throw new Error(
|
|
61
|
-
`${result.status}: ${result.statusText} when using doc search tool. Details: ${
|
|
85
|
+
`${result.status}: ${result.statusText} when using doc search tool. Details: ${errorText}`,
|
|
62
86
|
);
|
|
63
87
|
}
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
const resultBody = await result.json();
|
|
90
|
+
logger.info(
|
|
91
|
+
{
|
|
92
|
+
durationMs: Date.now() - startTime,
|
|
93
|
+
query: body.query,
|
|
94
|
+
},
|
|
95
|
+
'Got docs search result',
|
|
96
|
+
);
|
|
97
|
+
return asTextContentResult(resultBody);
|
|
66
98
|
};
|
|
67
99
|
|
|
68
100
|
export default { metadata, tool, handler };
|
package/src/http.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
|
4
4
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
5
|
import { ClientOptions } from '@zavudev/sdk';
|
|
6
6
|
import express from 'express';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import pino from 'pino';
|
|
8
|
+
import pinoHttp from 'pino-http';
|
|
9
9
|
import { getStainlessApiKey, parseClientAuthHeaders } from './auth';
|
|
10
|
+
import { getLogger } from './logger';
|
|
10
11
|
import { McpOptions } from './options';
|
|
11
12
|
import { initMcpServer, newMcpServer } from './server';
|
|
12
13
|
|
|
@@ -70,29 +71,60 @@ const del = async (req: express.Request, res: express.Response) => {
|
|
|
70
71
|
});
|
|
71
72
|
};
|
|
72
73
|
|
|
74
|
+
const redactHeaders = (headers: Record<string, any>) => {
|
|
75
|
+
const hiddenHeaders = /auth|cookie|key|token/i;
|
|
76
|
+
const filtered = { ...headers };
|
|
77
|
+
Object.keys(filtered).forEach((key) => {
|
|
78
|
+
if (hiddenHeaders.test(key)) {
|
|
79
|
+
filtered[key] = '[REDACTED]';
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return filtered;
|
|
83
|
+
};
|
|
84
|
+
|
|
73
85
|
export const streamableHTTPApp = ({
|
|
74
86
|
clientOptions = {},
|
|
75
87
|
mcpOptions,
|
|
76
|
-
debug,
|
|
77
88
|
}: {
|
|
78
89
|
clientOptions?: ClientOptions;
|
|
79
90
|
mcpOptions: McpOptions;
|
|
80
|
-
debug: boolean;
|
|
81
91
|
}): express.Express => {
|
|
82
92
|
const app = express();
|
|
83
93
|
app.set('query parser', 'extended');
|
|
84
94
|
app.use(express.json());
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
app.use(
|
|
96
|
+
pinoHttp({
|
|
97
|
+
logger: getLogger(),
|
|
98
|
+
customLogLevel: (req, res) => {
|
|
99
|
+
if (res.statusCode >= 500) {
|
|
100
|
+
return 'error';
|
|
101
|
+
} else if (res.statusCode >= 400) {
|
|
102
|
+
return 'warn';
|
|
103
|
+
}
|
|
104
|
+
return 'info';
|
|
105
|
+
},
|
|
106
|
+
customSuccessMessage: function (req, res) {
|
|
107
|
+
return `Request ${req.method} to ${req.url} completed with status ${res.statusCode}`;
|
|
108
|
+
},
|
|
109
|
+
customErrorMessage: function (req, res, err) {
|
|
110
|
+
return `Request ${req.method} to ${req.url} errored with status ${res.statusCode}`;
|
|
111
|
+
},
|
|
112
|
+
serializers: {
|
|
113
|
+
req: pino.stdSerializers.wrapRequestSerializer((req) => {
|
|
114
|
+
return {
|
|
115
|
+
...req,
|
|
116
|
+
headers: redactHeaders(req.raw.headers),
|
|
117
|
+
};
|
|
118
|
+
}),
|
|
119
|
+
res: pino.stdSerializers.wrapResponseSerializer((res) => {
|
|
120
|
+
return {
|
|
121
|
+
...res,
|
|
122
|
+
headers: redactHeaders(res.headers),
|
|
123
|
+
};
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
96
128
|
|
|
97
129
|
app.get('/health', async (req: express.Request, res: express.Response) => {
|
|
98
130
|
res.status(200).send('OK');
|
|
@@ -106,22 +138,22 @@ export const streamableHTTPApp = ({
|
|
|
106
138
|
|
|
107
139
|
export const launchStreamableHTTPServer = async ({
|
|
108
140
|
mcpOptions,
|
|
109
|
-
debug,
|
|
110
141
|
port,
|
|
111
142
|
}: {
|
|
112
143
|
mcpOptions: McpOptions;
|
|
113
|
-
debug: boolean;
|
|
114
144
|
port: number | string | undefined;
|
|
115
145
|
}) => {
|
|
116
|
-
const app = streamableHTTPApp({ mcpOptions
|
|
146
|
+
const app = streamableHTTPApp({ mcpOptions });
|
|
117
147
|
const server = app.listen(port);
|
|
118
148
|
const address = server.address();
|
|
119
149
|
|
|
150
|
+
const logger = getLogger();
|
|
151
|
+
|
|
120
152
|
if (typeof address === 'string') {
|
|
121
|
-
|
|
153
|
+
logger.info(`MCP Server running on streamable HTTP at ${address}`);
|
|
122
154
|
} else if (address !== null) {
|
|
123
|
-
|
|
155
|
+
logger.info(`MCP Server running on streamable HTTP on port ${address.port}`);
|
|
124
156
|
} else {
|
|
125
|
-
|
|
157
|
+
logger.info(`MCP Server running on streamable HTTP on port ${port}`);
|
|
126
158
|
}
|
|
127
159
|
};
|
package/src/index.ts
CHANGED
|
@@ -5,15 +5,20 @@ import { McpOptions, parseCLIOptions } from './options';
|
|
|
5
5
|
import { launchStdioServer } from './stdio';
|
|
6
6
|
import { launchStreamableHTTPServer } from './http';
|
|
7
7
|
import type { McpTool } from './types';
|
|
8
|
+
import { configureLogger, getLogger } from './logger';
|
|
8
9
|
|
|
9
10
|
async function main() {
|
|
10
11
|
const options = parseOptionsOrError();
|
|
12
|
+
configureLogger({
|
|
13
|
+
level: options.debug ? 'debug' : 'info',
|
|
14
|
+
pretty: options.logFormat === 'pretty',
|
|
15
|
+
});
|
|
11
16
|
|
|
12
17
|
const selectedTools = await selectToolsOrError(options);
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
selectedTools.
|
|
19
|
+
getLogger().info(
|
|
20
|
+
{ tools: selectedTools.map((e) => e.tool.name) },
|
|
21
|
+
`MCP Server starting with ${selectedTools.length} tools`,
|
|
17
22
|
);
|
|
18
23
|
|
|
19
24
|
switch (options.transport) {
|
|
@@ -23,7 +28,6 @@ async function main() {
|
|
|
23
28
|
case 'http':
|
|
24
29
|
await launchStreamableHTTPServer({
|
|
25
30
|
mcpOptions: options,
|
|
26
|
-
debug: options.debug,
|
|
27
31
|
port: options.socket ?? options.port,
|
|
28
32
|
});
|
|
29
33
|
break;
|
|
@@ -32,7 +36,8 @@ async function main() {
|
|
|
32
36
|
|
|
33
37
|
if (require.main === module) {
|
|
34
38
|
main().catch((error) => {
|
|
35
|
-
|
|
39
|
+
// Logger might not be initialized yet
|
|
40
|
+
console.error('Fatal error in main()', error);
|
|
36
41
|
process.exit(1);
|
|
37
42
|
});
|
|
38
43
|
}
|
|
@@ -41,7 +46,8 @@ function parseOptionsOrError() {
|
|
|
41
46
|
try {
|
|
42
47
|
return parseCLIOptions();
|
|
43
48
|
} catch (error) {
|
|
44
|
-
|
|
49
|
+
// Logger is initialized after options, so use console.error here
|
|
50
|
+
console.error('Error parsing options', error);
|
|
45
51
|
process.exit(1);
|
|
46
52
|
}
|
|
47
53
|
}
|
|
@@ -50,16 +56,12 @@ async function selectToolsOrError(options: McpOptions): Promise<McpTool[]> {
|
|
|
50
56
|
try {
|
|
51
57
|
const includedTools = selectTools(options);
|
|
52
58
|
if (includedTools.length === 0) {
|
|
53
|
-
|
|
59
|
+
getLogger().error('No tools match the provided filters');
|
|
54
60
|
process.exit(1);
|
|
55
61
|
}
|
|
56
62
|
return includedTools;
|
|
57
63
|
} catch (error) {
|
|
58
|
-
|
|
59
|
-
console.error('Error filtering tools:', error.message);
|
|
60
|
-
} else {
|
|
61
|
-
console.error('Error filtering tools:', error);
|
|
62
|
-
}
|
|
64
|
+
getLogger().error({ error }, 'Error filtering tools');
|
|
63
65
|
process.exit(1);
|
|
64
66
|
}
|
|
65
67
|
}
|
package/src/instructions.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { readEnv } from './util';
|
|
4
|
+
import { getLogger } from './logger';
|
|
4
5
|
|
|
5
6
|
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
6
7
|
|
|
@@ -50,25 +51,15 @@ async function fetchLatestInstructions(stainlessApiKey: string | undefined): Pro
|
|
|
50
51
|
|
|
51
52
|
let instructions: string | undefined;
|
|
52
53
|
if (!response.ok) {
|
|
53
|
-
|
|
54
|
+
getLogger().warn(
|
|
54
55
|
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
55
56
|
);
|
|
56
57
|
|
|
57
|
-
instructions =
|
|
58
|
-
This is the zavudev MCP server.
|
|
59
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
60
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
61
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
62
|
-
block: it can be as long as you need to get the job done!
|
|
63
|
-
`;
|
|
58
|
+
instructions =
|
|
59
|
+
'\n This is the zavudev MCP server.\n\n Available tools:\n - search_docs: Search SDK documentation to find the right methods and parameters.\n - execute: Run TypeScript code against a pre-authenticated SDK client. Define an async run(client) function.\n\n Workflow:\n - If unsure about the API, call search_docs first.\n - Write complete solutions in a single execute call when possible. For large datasets, use API filters to narrow results or paginate within a single execute block.\n - If execute returns an error, read the error and fix your code rather than retrying the same approach.\n - Variables do not persist between execute calls. Return or log all data you need.\n - Individual HTTP requests to the API have a 30-second timeout. If a request times out, try a smaller query or add filters.\n - Code execution has a total timeout of approximately 5 minutes. If your code times out, simplify it or break it into smaller steps.\n ';
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
67
|
-
instructions = `
|
|
68
|
-
If needed, you can get the current time by executing Date.now().
|
|
69
|
-
|
|
70
|
-
${instructions}
|
|
71
|
-
`;
|
|
72
63
|
|
|
73
64
|
return instructions;
|
|
74
65
|
}
|
package/src/logger.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { pino, type Level, type Logger } from 'pino';
|
|
4
|
+
import pretty from 'pino-pretty';
|
|
5
|
+
|
|
6
|
+
let _logger: Logger | undefined;
|
|
7
|
+
|
|
8
|
+
export function configureLogger({ level, pretty: usePretty }: { level: Level; pretty: boolean }): void {
|
|
9
|
+
_logger = pino(
|
|
10
|
+
{
|
|
11
|
+
level,
|
|
12
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
13
|
+
formatters: {
|
|
14
|
+
level(label) {
|
|
15
|
+
return { level: label };
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
usePretty ? pretty({ colorize: true, levelFirst: true, destination: 2 }) : process.stderr,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getLogger(): Logger {
|
|
24
|
+
if (!_logger) {
|
|
25
|
+
throw new Error('Logger has not been configured. Call configureLogger() before using the logger.');
|
|
26
|
+
}
|
|
27
|
+
return _logger;
|
|
28
|
+
}
|
package/src/options.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { readEnv } from './util';
|
|
|
8
8
|
|
|
9
9
|
export type CLIOptions = McpOptions & {
|
|
10
10
|
debug: boolean;
|
|
11
|
+
logFormat: 'json' | 'pretty';
|
|
11
12
|
transport: 'stdio' | 'http';
|
|
12
13
|
port: number | undefined;
|
|
13
14
|
socket: string | undefined;
|
|
@@ -52,6 +53,11 @@ export function parseCLIOptions(): CLIOptions {
|
|
|
52
53
|
"Where to run code execution in code tool; 'stainless-sandbox' will execute code in Stainless-hosted sandboxes whereas 'local' will execute code locally on the MCP server machine.",
|
|
53
54
|
})
|
|
54
55
|
.option('debug', { type: 'boolean', description: 'Enable debug logging' })
|
|
56
|
+
.option('log-format', {
|
|
57
|
+
type: 'string',
|
|
58
|
+
choices: ['json', 'pretty'],
|
|
59
|
+
description: 'Format for log output; defaults to json unless tty is detected',
|
|
60
|
+
})
|
|
55
61
|
.option('no-tools', {
|
|
56
62
|
type: 'string',
|
|
57
63
|
array: true,
|
|
@@ -97,6 +103,10 @@ export function parseCLIOptions(): CLIOptions {
|
|
|
97
103
|
const includeDocsTools = shouldIncludeToolType('docs');
|
|
98
104
|
|
|
99
105
|
const transport = argv.transport as 'stdio' | 'http';
|
|
106
|
+
const logFormat =
|
|
107
|
+
argv.logFormat ? (argv.logFormat as 'json' | 'pretty')
|
|
108
|
+
: process.stderr.isTTY ? 'pretty'
|
|
109
|
+
: 'json';
|
|
100
110
|
|
|
101
111
|
return {
|
|
102
112
|
...(includeCodeTool !== undefined && { includeCodeTool }),
|
|
@@ -108,6 +118,7 @@ export function parseCLIOptions(): CLIOptions {
|
|
|
108
118
|
codeBlockedMethods: argv.codeBlockedMethods,
|
|
109
119
|
codeExecutionMode: argv.codeExecutionMode as McpCodeExecutionMode,
|
|
110
120
|
transport,
|
|
121
|
+
logFormat,
|
|
111
122
|
port: argv.port,
|
|
112
123
|
socket: argv.socket,
|
|
113
124
|
};
|
package/src/server.ts
CHANGED
package/src/stdio.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
2
|
import { McpOptions } from './options';
|
|
3
3
|
import { initMcpServer, newMcpServer } from './server';
|
|
4
|
+
import { getLogger } from './logger';
|
|
4
5
|
|
|
5
6
|
export const launchStdioServer = async (mcpOptions: McpOptions) => {
|
|
6
7
|
const server = await newMcpServer(mcpOptions.stainlessApiKey);
|
|
@@ -9,5 +10,5 @@ export const launchStdioServer = async (mcpOptions: McpOptions) => {
|
|
|
9
10
|
|
|
10
11
|
const transport = new StdioServerTransport();
|
|
11
12
|
await server.connect(transport);
|
|
12
|
-
|
|
13
|
+
getLogger().info('MCP Server running on stdio');
|
|
13
14
|
};
|
package/stdio.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.mts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"stdio.d.mts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;AAIrB,eAAO,MAAM,iBAAiB,GAAU,YAAY,UAAU,kBAQ7D,CAAC"}
|
package/stdio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;AAIrB,eAAO,MAAM,iBAAiB,GAAU,YAAY,UAAU,kBAQ7D,CAAC"}
|
package/stdio.js
CHANGED
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.launchStdioServer = void 0;
|
|
4
4
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
5
5
|
const server_1 = require("./server.js");
|
|
6
|
+
const logger_1 = require("./logger.js");
|
|
6
7
|
const launchStdioServer = async (mcpOptions) => {
|
|
7
8
|
const server = await (0, server_1.newMcpServer)(mcpOptions.stainlessApiKey);
|
|
8
9
|
await (0, server_1.initMcpServer)({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey });
|
|
9
10
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
10
11
|
await server.connect(transport);
|
|
11
|
-
|
|
12
|
+
(0, logger_1.getLogger)().info('MCP Server running on stdio');
|
|
12
13
|
};
|
|
13
14
|
exports.launchStdioServer = launchStdioServer;
|
|
14
15
|
//# sourceMappingURL=stdio.js.map
|
package/stdio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":";;;AAAA,wEAAiF;AAEjF,wCAAuD;
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":";;;AAAA,wEAAiF;AAEjF,wCAAuD;AACvD,wCAAqC;AAE9B,MAAM,iBAAiB,GAAG,KAAK,EAAE,UAAsB,EAAE,EAAE;IAChE,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAE9D,MAAM,IAAA,sBAAa,EAAC,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC;IAEzF,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,IAAA,kBAAS,GAAE,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAClD,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B"}
|
package/stdio.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
2
2
|
import { initMcpServer, newMcpServer } from "./server.mjs";
|
|
3
|
+
import { getLogger } from "./logger.mjs";
|
|
3
4
|
export const launchStdioServer = async (mcpOptions) => {
|
|
4
5
|
const server = await newMcpServer(mcpOptions.stainlessApiKey);
|
|
5
6
|
await initMcpServer({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey });
|
|
6
7
|
const transport = new StdioServerTransport();
|
|
7
8
|
await server.connect(transport);
|
|
8
|
-
|
|
9
|
+
getLogger().info('MCP Server running on stdio');
|
|
9
10
|
};
|
|
10
11
|
//# sourceMappingURL=stdio.mjs.map
|
package/stdio.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stdio.mjs","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C;OAEzE,EAAE,aAAa,EAAE,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"stdio.mjs","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C;OAEzE,EAAE,aAAa,EAAE,YAAY,EAAE;OAC/B,EAAE,SAAS,EAAE;AAEpB,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,UAAsB,EAAE,EAAE;IAChE,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IAE9D,MAAM,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC;IAEzF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,SAAS,EAAE,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAClD,CAAC,CAAC"}
|