@stigg/typescript-mcp 0.1.0-alpha.8

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 (112) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -0
  3. package/auth.d.mts +6 -0
  4. package/auth.d.mts.map +1 -0
  5. package/auth.d.ts +6 -0
  6. package/auth.d.ts.map +1 -0
  7. package/auth.js +22 -0
  8. package/auth.js.map +1 -0
  9. package/auth.mjs +17 -0
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-types.d.mts +14 -0
  12. package/code-tool-types.d.mts.map +1 -0
  13. package/code-tool-types.d.ts +14 -0
  14. package/code-tool-types.d.ts.map +1 -0
  15. package/code-tool-types.js +4 -0
  16. package/code-tool-types.js.map +1 -0
  17. package/code-tool-types.mjs +3 -0
  18. package/code-tool-types.mjs.map +1 -0
  19. package/code-tool.d.mts +15 -0
  20. package/code-tool.d.mts.map +1 -0
  21. package/code-tool.d.ts +15 -0
  22. package/code-tool.d.ts.map +1 -0
  23. package/code-tool.js +108 -0
  24. package/code-tool.js.map +1 -0
  25. package/code-tool.mjs +105 -0
  26. package/code-tool.mjs.map +1 -0
  27. package/docs-search-tool.d.mts +57 -0
  28. package/docs-search-tool.d.mts.map +1 -0
  29. package/docs-search-tool.d.ts +57 -0
  30. package/docs-search-tool.d.ts.map +1 -0
  31. package/docs-search-tool.js +55 -0
  32. package/docs-search-tool.js.map +1 -0
  33. package/docs-search-tool.mjs +51 -0
  34. package/docs-search-tool.mjs.map +1 -0
  35. package/http.d.mts +14 -0
  36. package/http.d.mts.map +1 -0
  37. package/http.d.ts +14 -0
  38. package/http.d.ts.map +1 -0
  39. package/http.js +107 -0
  40. package/http.js.map +1 -0
  41. package/http.mjs +99 -0
  42. package/http.mjs.map +1 -0
  43. package/index.d.mts +3 -0
  44. package/index.d.mts.map +1 -0
  45. package/index.d.ts +3 -0
  46. package/index.d.ts.map +1 -0
  47. package/index.js +59 -0
  48. package/index.js.map +1 -0
  49. package/index.mjs +57 -0
  50. package/index.mjs.map +1 -0
  51. package/methods.d.mts +10 -0
  52. package/methods.d.mts.map +1 -0
  53. package/methods.d.ts +10 -0
  54. package/methods.d.ts.map +1 -0
  55. package/methods.js +419 -0
  56. package/methods.js.map +1 -0
  57. package/methods.mjs +415 -0
  58. package/methods.mjs.map +1 -0
  59. package/options.d.mts +16 -0
  60. package/options.d.mts.map +1 -0
  61. package/options.d.ts +16 -0
  62. package/options.d.ts.map +1 -0
  63. package/options.js +99 -0
  64. package/options.js.map +1 -0
  65. package/options.mjs +92 -0
  66. package/options.mjs.map +1 -0
  67. package/package.json +185 -0
  68. package/server.d.mts +29 -0
  69. package/server.d.mts.map +1 -0
  70. package/server.d.ts +29 -0
  71. package/server.d.ts.map +1 -0
  72. package/server.js +143 -0
  73. package/server.js.map +1 -0
  74. package/server.mjs +133 -0
  75. package/server.mjs.map +1 -0
  76. package/src/auth.ts +25 -0
  77. package/src/code-tool-types.ts +16 -0
  78. package/src/code-tool.ts +139 -0
  79. package/src/docs-search-tool.ts +68 -0
  80. package/src/http.ts +138 -0
  81. package/src/index.ts +65 -0
  82. package/src/methods.ts +440 -0
  83. package/src/options.ts +129 -0
  84. package/src/server.ts +181 -0
  85. package/src/stdio.ts +13 -0
  86. package/src/tsconfig.json +11 -0
  87. package/src/types.ts +123 -0
  88. package/src/util.ts +25 -0
  89. package/stdio.d.mts +3 -0
  90. package/stdio.d.mts.map +1 -0
  91. package/stdio.d.ts +3 -0
  92. package/stdio.d.ts.map +1 -0
  93. package/stdio.js +14 -0
  94. package/stdio.js.map +1 -0
  95. package/stdio.mjs +10 -0
  96. package/stdio.mjs.map +1 -0
  97. package/types.d.mts +59 -0
  98. package/types.d.mts.map +1 -0
  99. package/types.d.ts +59 -0
  100. package/types.d.ts.map +1 -0
  101. package/types.js +58 -0
  102. package/types.js.map +1 -0
  103. package/types.mjs +53 -0
  104. package/types.mjs.map +1 -0
  105. package/util.d.mts +4 -0
  106. package/util.d.mts.map +1 -0
  107. package/util.d.ts +4 -0
  108. package/util.d.ts.map +1 -0
  109. package/util.js +30 -0
  110. package/util.js.map +1 -0
  111. package/util.mjs +24 -0
  112. package/util.mjs.map +1 -0
package/src/server.ts ADDED
@@ -0,0 +1,181 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import {
6
+ CallToolRequestSchema,
7
+ ListToolsRequestSchema,
8
+ SetLevelRequestSchema,
9
+ } from '@modelcontextprotocol/sdk/types.js';
10
+ import { ClientOptions } from '@stigg/typescript';
11
+ import Stigg from '@stigg/typescript';
12
+ import { codeTool } from './code-tool';
13
+ import docsSearchTool from './docs-search-tool';
14
+ import { McpOptions } from './options';
15
+ import { blockedMethodsForCodeTool } from './methods';
16
+ import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from './types';
17
+ import { readEnv } from './util';
18
+
19
+ async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
20
+ // Setting the stainless API key is optional, but may be required
21
+ // to authenticate requests to the Stainless API.
22
+ const response = await fetch(
23
+ readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/stigg',
24
+ {
25
+ method: 'GET',
26
+ headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
27
+ },
28
+ );
29
+
30
+ let instructions: string | undefined;
31
+ if (!response.ok) {
32
+ console.warn(
33
+ 'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
34
+ );
35
+
36
+ instructions = `
37
+ This is the stigg MCP server. You will use Code Mode to help the user perform
38
+ actions. You can use search_docs tool to learn about how to take action with this server. Then,
39
+ you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
40
+ thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
41
+ block: it can be as long as you need to get the job done!
42
+ `;
43
+ }
44
+
45
+ instructions ??= ((await response.json()) as { instructions: string }).instructions;
46
+ instructions = `
47
+ The current time in Unix timestamps is ${Date.now()}.
48
+
49
+ ${instructions}
50
+ `;
51
+
52
+ return instructions;
53
+ }
54
+
55
+ export const newMcpServer = async (stainlessApiKey: string | undefined) =>
56
+ new McpServer(
57
+ {
58
+ name: 'stigg_typescript_api',
59
+ version: '0.1.0-alpha.8',
60
+ },
61
+ {
62
+ instructions: await getInstructions(stainlessApiKey),
63
+ capabilities: { tools: {}, logging: {} },
64
+ },
65
+ );
66
+
67
+ /**
68
+ * Initializes the provided MCP Server with the given tools and handlers.
69
+ * If not provided, the default client, tools and handlers will be used.
70
+ */
71
+ export async function initMcpServer(params: {
72
+ server: Server | McpServer;
73
+ clientOptions?: ClientOptions;
74
+ mcpOptions?: McpOptions;
75
+ stainlessApiKey?: string | undefined;
76
+ }) {
77
+ const server = params.server instanceof McpServer ? params.server.server : params.server;
78
+
79
+ const logAtLevel =
80
+ (level: 'debug' | 'info' | 'warning' | 'error') =>
81
+ (message: string, ...rest: unknown[]) => {
82
+ void server.sendLoggingMessage({
83
+ level,
84
+ data: { message, rest },
85
+ });
86
+ };
87
+ const logger = {
88
+ debug: logAtLevel('debug'),
89
+ info: logAtLevel('info'),
90
+ warn: logAtLevel('warning'),
91
+ error: logAtLevel('error'),
92
+ };
93
+
94
+ let client = new Stigg({
95
+ logger,
96
+ ...params.clientOptions,
97
+ defaultHeaders: {
98
+ ...params.clientOptions?.defaultHeaders,
99
+ 'X-Stainless-MCP': 'true',
100
+ },
101
+ });
102
+
103
+ const providedTools = selectTools(params.mcpOptions);
104
+ const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
105
+
106
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
107
+ return {
108
+ tools: providedTools.map((mcpTool) => mcpTool.tool),
109
+ };
110
+ });
111
+
112
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
113
+ const { name, arguments: args } = request.params;
114
+ const mcpTool = toolMap[name];
115
+ if (!mcpTool) {
116
+ throw new Error(`Unknown tool: ${name}`);
117
+ }
118
+
119
+ return executeHandler({
120
+ handler: mcpTool.handler,
121
+ reqContext: {
122
+ client,
123
+ stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
124
+ },
125
+ args,
126
+ });
127
+ });
128
+
129
+ server.setRequestHandler(SetLevelRequestSchema, async (request) => {
130
+ const { level } = request.params;
131
+ switch (level) {
132
+ case 'debug':
133
+ client = client.withOptions({ logLevel: 'debug' });
134
+ break;
135
+ case 'info':
136
+ client = client.withOptions({ logLevel: 'info' });
137
+ break;
138
+ case 'notice':
139
+ case 'warning':
140
+ client = client.withOptions({ logLevel: 'warn' });
141
+ break;
142
+ case 'error':
143
+ client = client.withOptions({ logLevel: 'error' });
144
+ break;
145
+ default:
146
+ client = client.withOptions({ logLevel: 'off' });
147
+ break;
148
+ }
149
+ return {};
150
+ });
151
+ }
152
+
153
+ /**
154
+ * Selects the tools to include in the MCP Server based on the provided options.
155
+ */
156
+ export function selectTools(options?: McpOptions): McpTool[] {
157
+ const includedTools = [
158
+ codeTool({
159
+ blockedMethods: blockedMethodsForCodeTool(options),
160
+ }),
161
+ ];
162
+ if (options?.includeDocsTools ?? true) {
163
+ includedTools.push(docsSearchTool);
164
+ }
165
+ return includedTools;
166
+ }
167
+
168
+ /**
169
+ * Runs the provided handler with the given client and arguments.
170
+ */
171
+ export async function executeHandler({
172
+ handler,
173
+ reqContext,
174
+ args,
175
+ }: {
176
+ handler: HandlerFunction;
177
+ reqContext: McpRequestContext;
178
+ args: Record<string, unknown> | undefined;
179
+ }): Promise<ToolCallResult> {
180
+ return await handler({ reqContext, args: args || {} });
181
+ }
package/src/stdio.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2
+ import { McpOptions } from './options';
3
+ import { initMcpServer, newMcpServer } from './server';
4
+
5
+ export const launchStdioServer = async (mcpOptions: McpOptions) => {
6
+ const server = await newMcpServer(mcpOptions.stainlessApiKey);
7
+
8
+ await initMcpServer({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey });
9
+
10
+ const transport = new StdioServerTransport();
11
+ await server.connect(transport);
12
+ console.error('MCP Server running on stdio');
13
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ // this config is included in the published src directory to prevent TS errors
3
+ // from appearing when users go to source, and VSCode opens the source .ts file
4
+ // via declaration maps
5
+ "include": ["index.ts"],
6
+ "compilerOptions": {
7
+ "target": "es2015",
8
+ "lib": ["DOM"],
9
+ "moduleResolution": "node"
10
+ }
11
+ }
package/src/types.ts ADDED
@@ -0,0 +1,123 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import Stigg from '@stigg/typescript';
4
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
5
+
6
+ type TextContentBlock = {
7
+ type: 'text';
8
+ text: string;
9
+ };
10
+
11
+ type ImageContentBlock = {
12
+ type: 'image';
13
+ data: string;
14
+ mimeType: string;
15
+ };
16
+
17
+ type AudioContentBlock = {
18
+ type: 'audio';
19
+ data: string;
20
+ mimeType: string;
21
+ };
22
+
23
+ type ResourceContentBlock = {
24
+ type: 'resource';
25
+ resource:
26
+ | {
27
+ uri: string;
28
+ mimeType: string;
29
+ text: string;
30
+ }
31
+ | {
32
+ uri: string;
33
+ mimeType: string;
34
+ blob: string;
35
+ };
36
+ };
37
+
38
+ export type ContentBlock = TextContentBlock | ImageContentBlock | AudioContentBlock | ResourceContentBlock;
39
+
40
+ export type ToolCallResult = {
41
+ content: ContentBlock[];
42
+ isError?: boolean;
43
+ };
44
+
45
+ export type McpRequestContext = {
46
+ client: Stigg;
47
+ stainlessApiKey?: string | undefined;
48
+ };
49
+
50
+ export type HandlerFunction = ({
51
+ reqContext,
52
+ args,
53
+ }: {
54
+ reqContext: McpRequestContext;
55
+ args: Record<string, unknown> | undefined;
56
+ }) => Promise<ToolCallResult>;
57
+
58
+ export function asTextContentResult(result: unknown): ToolCallResult {
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text',
63
+ text: JSON.stringify(result, null, 2),
64
+ },
65
+ ],
66
+ };
67
+ }
68
+
69
+ export async function asBinaryContentResult(response: Response): Promise<ToolCallResult> {
70
+ const blob = await response.blob();
71
+ const mimeType = blob.type;
72
+ const data = Buffer.from(await blob.arrayBuffer()).toString('base64');
73
+ if (mimeType.startsWith('image/')) {
74
+ return {
75
+ content: [{ type: 'image', mimeType, data }],
76
+ };
77
+ } else if (mimeType.startsWith('audio/')) {
78
+ return {
79
+ content: [{ type: 'audio', mimeType, data }],
80
+ };
81
+ } else {
82
+ return {
83
+ content: [
84
+ {
85
+ type: 'resource',
86
+ resource: {
87
+ // We must give a URI, even though this isn't actually an MCP resource.
88
+ uri: 'resource://tool-response',
89
+ mimeType,
90
+ blob: data,
91
+ },
92
+ },
93
+ ],
94
+ };
95
+ }
96
+ }
97
+
98
+ export function asErrorResult(message: string): ToolCallResult {
99
+ return {
100
+ content: [
101
+ {
102
+ type: 'text',
103
+ text: message,
104
+ },
105
+ ],
106
+ isError: true,
107
+ };
108
+ }
109
+
110
+ export type Metadata = {
111
+ resource: string;
112
+ operation: 'read' | 'write';
113
+ tags: string[];
114
+ httpMethod?: string;
115
+ httpPath?: string;
116
+ operationId?: string;
117
+ };
118
+
119
+ export type McpTool = {
120
+ metadata: Metadata;
121
+ tool: Tool;
122
+ handler: HandlerFunction;
123
+ };
package/src/util.ts ADDED
@@ -0,0 +1,25 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export const readEnv = (env: string): string | undefined => {
4
+ if (typeof (globalThis as any).process !== 'undefined') {
5
+ return (globalThis as any).process.env?.[env]?.trim();
6
+ } else if (typeof (globalThis as any).Deno !== 'undefined') {
7
+ return (globalThis as any).Deno.env?.get?.(env)?.trim();
8
+ }
9
+ return;
10
+ };
11
+
12
+ export const readEnvOrError = (env: string): string => {
13
+ let envValue = readEnv(env);
14
+ if (envValue === undefined) {
15
+ throw new Error(`Environment variable ${env} is not set`);
16
+ }
17
+ return envValue;
18
+ };
19
+
20
+ export const requireValue = <T>(value: T | undefined, description: string): T => {
21
+ if (value === undefined) {
22
+ throw new Error(`Missing required value: ${description}`);
23
+ }
24
+ return value;
25
+ };
package/stdio.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ import { McpOptions } from "./options.mjs";
2
+ export declare const launchStdioServer: (mcpOptions: McpOptions) => Promise<void>;
3
+ //# sourceMappingURL=stdio.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.d.mts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;AAGrB,eAAO,MAAM,iBAAiB,GAAU,YAAY,UAAU,kBAQ7D,CAAC"}
package/stdio.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { McpOptions } from "./options.js";
2
+ export declare const launchStdioServer: (mcpOptions: McpOptions) => Promise<void>;
3
+ //# sourceMappingURL=stdio.d.ts.map
package/stdio.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":"OACO,EAAE,UAAU,EAAE;AAGrB,eAAO,MAAM,iBAAiB,GAAU,YAAY,UAAU,kBAQ7D,CAAC"}
package/stdio.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.launchStdioServer = void 0;
4
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
5
+ const server_1 = require("./server.js");
6
+ const launchStdioServer = async (mcpOptions) => {
7
+ const server = await (0, server_1.newMcpServer)(mcpOptions.stainlessApiKey);
8
+ await (0, server_1.initMcpServer)({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey });
9
+ const transport = new stdio_js_1.StdioServerTransport();
10
+ await server.connect(transport);
11
+ console.error('MCP Server running on stdio');
12
+ };
13
+ exports.launchStdioServer = launchStdioServer;
14
+ //# sourceMappingURL=stdio.js.map
package/stdio.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.js","sourceRoot":"","sources":["src/stdio.ts"],"names":[],"mappings":";;;AAAA,wEAAiF;AAEjF,wCAAuD;AAEhD,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,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAC/C,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B"}
package/stdio.mjs ADDED
@@ -0,0 +1,10 @@
1
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
2
+ import { initMcpServer, newMcpServer } from "./server.mjs";
3
+ export const launchStdioServer = async (mcpOptions) => {
4
+ const server = await newMcpServer(mcpOptions.stainlessApiKey);
5
+ await initMcpServer({ server, mcpOptions, stainlessApiKey: mcpOptions.stainlessApiKey });
6
+ const transport = new StdioServerTransport();
7
+ await server.connect(transport);
8
+ console.error('MCP Server running on stdio');
9
+ };
10
+ //# sourceMappingURL=stdio.mjs.map
package/stdio.mjs.map ADDED
@@ -0,0 +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;AAEtC,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,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAC/C,CAAC,CAAC"}
package/types.d.mts ADDED
@@ -0,0 +1,59 @@
1
+ import Stigg from '@stigg/typescript';
2
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ type TextContentBlock = {
4
+ type: 'text';
5
+ text: string;
6
+ };
7
+ type ImageContentBlock = {
8
+ type: 'image';
9
+ data: string;
10
+ mimeType: string;
11
+ };
12
+ type AudioContentBlock = {
13
+ type: 'audio';
14
+ data: string;
15
+ mimeType: string;
16
+ };
17
+ type ResourceContentBlock = {
18
+ type: 'resource';
19
+ resource: {
20
+ uri: string;
21
+ mimeType: string;
22
+ text: string;
23
+ } | {
24
+ uri: string;
25
+ mimeType: string;
26
+ blob: string;
27
+ };
28
+ };
29
+ export type ContentBlock = TextContentBlock | ImageContentBlock | AudioContentBlock | ResourceContentBlock;
30
+ export type ToolCallResult = {
31
+ content: ContentBlock[];
32
+ isError?: boolean;
33
+ };
34
+ export type McpRequestContext = {
35
+ client: Stigg;
36
+ stainlessApiKey?: string | undefined;
37
+ };
38
+ export type HandlerFunction = ({ reqContext, args, }: {
39
+ reqContext: McpRequestContext;
40
+ args: Record<string, unknown> | undefined;
41
+ }) => Promise<ToolCallResult>;
42
+ export declare function asTextContentResult(result: unknown): ToolCallResult;
43
+ export declare function asBinaryContentResult(response: Response): Promise<ToolCallResult>;
44
+ export declare function asErrorResult(message: string): ToolCallResult;
45
+ export type Metadata = {
46
+ resource: string;
47
+ operation: 'read' | 'write';
48
+ tags: string[];
49
+ httpMethod?: string;
50
+ httpPath?: string;
51
+ operationId?: string;
52
+ };
53
+ export type McpTool = {
54
+ metadata: Metadata;
55
+ tool: Tool;
56
+ handler: HandlerFunction;
57
+ };
58
+ export {};
59
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"OAEO,KAAK,MAAM,mBAAmB;OAC9B,EAAE,IAAI,EAAE,MAAM,oCAAoC;AAEzD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EACJ;QACE,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GACD;QACE,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACP,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAE3G,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,KAAK,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,EAC7B,UAAU,EACV,IAAI,GACL,EAAE;IACD,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE9B,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,CASnE;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,CA2BvF;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAU7D;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC"}
package/types.d.ts ADDED
@@ -0,0 +1,59 @@
1
+ import Stigg from '@stigg/typescript';
2
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ type TextContentBlock = {
4
+ type: 'text';
5
+ text: string;
6
+ };
7
+ type ImageContentBlock = {
8
+ type: 'image';
9
+ data: string;
10
+ mimeType: string;
11
+ };
12
+ type AudioContentBlock = {
13
+ type: 'audio';
14
+ data: string;
15
+ mimeType: string;
16
+ };
17
+ type ResourceContentBlock = {
18
+ type: 'resource';
19
+ resource: {
20
+ uri: string;
21
+ mimeType: string;
22
+ text: string;
23
+ } | {
24
+ uri: string;
25
+ mimeType: string;
26
+ blob: string;
27
+ };
28
+ };
29
+ export type ContentBlock = TextContentBlock | ImageContentBlock | AudioContentBlock | ResourceContentBlock;
30
+ export type ToolCallResult = {
31
+ content: ContentBlock[];
32
+ isError?: boolean;
33
+ };
34
+ export type McpRequestContext = {
35
+ client: Stigg;
36
+ stainlessApiKey?: string | undefined;
37
+ };
38
+ export type HandlerFunction = ({ reqContext, args, }: {
39
+ reqContext: McpRequestContext;
40
+ args: Record<string, unknown> | undefined;
41
+ }) => Promise<ToolCallResult>;
42
+ export declare function asTextContentResult(result: unknown): ToolCallResult;
43
+ export declare function asBinaryContentResult(response: Response): Promise<ToolCallResult>;
44
+ export declare function asErrorResult(message: string): ToolCallResult;
45
+ export type Metadata = {
46
+ resource: string;
47
+ operation: 'read' | 'write';
48
+ tags: string[];
49
+ httpMethod?: string;
50
+ httpPath?: string;
51
+ operationId?: string;
52
+ };
53
+ export type McpTool = {
54
+ metadata: Metadata;
55
+ tool: Tool;
56
+ handler: HandlerFunction;
57
+ };
58
+ export {};
59
+ //# sourceMappingURL=types.d.ts.map
package/types.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"OAEO,KAAK,MAAM,mBAAmB;OAC9B,EAAE,IAAI,EAAE,MAAM,oCAAoC;AAEzD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,I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EAAE,MAAM,EAAE,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,eAAe,CAAC;CAC1B,CAAC"}
package/types.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.asTextContentResult = asTextContentResult;
5
+ exports.asBinaryContentResult = asBinaryContentResult;
6
+ exports.asErrorResult = asErrorResult;
7
+ function asTextContentResult(result) {
8
+ return {
9
+ content: [
10
+ {
11
+ type: 'text',
12
+ text: JSON.stringify(result, null, 2),
13
+ },
14
+ ],
15
+ };
16
+ }
17
+ async function asBinaryContentResult(response) {
18
+ const blob = await response.blob();
19
+ const mimeType = blob.type;
20
+ const data = Buffer.from(await blob.arrayBuffer()).toString('base64');
21
+ if (mimeType.startsWith('image/')) {
22
+ return {
23
+ content: [{ type: 'image', mimeType, data }],
24
+ };
25
+ }
26
+ else if (mimeType.startsWith('audio/')) {
27
+ return {
28
+ content: [{ type: 'audio', mimeType, data }],
29
+ };
30
+ }
31
+ else {
32
+ return {
33
+ content: [
34
+ {
35
+ type: 'resource',
36
+ resource: {
37
+ // We must give a URI, even though this isn't actually an MCP resource.
38
+ uri: 'resource://tool-response',
39
+ mimeType,
40
+ blob: data,
41
+ },
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ }
47
+ function asErrorResult(message) {
48
+ return {
49
+ content: [
50
+ {
51
+ type: 'text',
52
+ text: message,
53
+ },
54
+ ],
55
+ isError: true,
56
+ };
57
+ }
58
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version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,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;aACd;SACF;QACD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
package/types.mjs ADDED
@@ -0,0 +1,53 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ export function asTextContentResult(result) {
3
+ return {
4
+ content: [
5
+ {
6
+ type: 'text',
7
+ text: JSON.stringify(result, null, 2),
8
+ },
9
+ ],
10
+ };
11
+ }
12
+ export async function asBinaryContentResult(response) {
13
+ const blob = await response.blob();
14
+ const mimeType = blob.type;
15
+ const data = Buffer.from(await blob.arrayBuffer()).toString('base64');
16
+ if (mimeType.startsWith('image/')) {
17
+ return {
18
+ content: [{ type: 'image', mimeType, data }],
19
+ };
20
+ }
21
+ else if (mimeType.startsWith('audio/')) {
22
+ return {
23
+ content: [{ type: 'audio', mimeType, data }],
24
+ };
25
+ }
26
+ else {
27
+ return {
28
+ content: [
29
+ {
30
+ type: 'resource',
31
+ resource: {
32
+ // We must give a URI, even though this isn't actually an MCP resource.
33
+ uri: 'resource://tool-response',
34
+ mimeType,
35
+ blob: data,
36
+ },
37
+ },
38
+ ],
39
+ };
40
+ }
41
+ }
42
+ export function asErrorResult(message) {
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: message,
48
+ },
49
+ ],
50
+ isError: true,
51
+ };
52
+ }
53
+ //# sourceMappingURL=types.mjs.map
package/types.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAyDtF,MAAM,UAAU,mBAAmB,CAAC,MAAe;IACjD,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACtC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAkB;IAC5D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;IAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACtE,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SAC7C,CAAC;IACJ,CAAC;SAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SAC7C,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,UAAU;oBAChB,QAAQ,EAAE;wBACR,uEAAuE;wBACvE,GAAG,EAAE,0BAA0B;wBAC/B,QAAQ;wBACR,IAAI,EAAE,IAAI;qBACX;iBACF;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO;aACd;SACF;QACD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
package/util.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const readEnv: (env: string) => string | undefined;
2
+ export declare const readEnvOrError: (env: string) => string;
3
+ export declare const requireValue: <T>(value: T | undefined, description: string) => T;
4
+ //# sourceMappingURL=util.d.mts.map
package/util.d.mts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.mts","sourceRoot":"","sources":["src/util.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAO9C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,MAM5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,aAAa,MAAM,KAAG,CAK3E,CAAC"}
package/util.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const readEnv: (env: string) => string | undefined;
2
+ export declare const readEnvOrError: (env: string) => string;
3
+ export declare const requireValue: <T>(value: T | undefined, description: string) => T;
4
+ //# sourceMappingURL=util.d.ts.map