@tigerdata/mcp-boilerplate 0.9.1 → 0.9.2
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/dist/http/api.d.ts +2 -3
- package/dist/http/mcp.d.ts +2 -1
- package/dist/http/mcp.js +6 -2
- package/dist/httpServer.d.ts +3 -4
- package/dist/httpServer.js +18 -3
- package/dist/mcpServer.d.ts +3 -4
- package/dist/mcpServer.js +2 -2
- package/dist/stdio.d.ts +3 -4
- package/dist/types.d.ts +34 -11
- package/package.json +3 -2
package/dist/http/api.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* REST API alternative to MCP for direct use of the same tools.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export declare const apiRouterFactory: <Context extends Record<string, unknown>>(context: Context, apiFactories: readonly ApiFactory<Context, ZodRawShape, ZodRawShape>[]) => RouterFactoryResult;
|
|
4
|
+
import type { BaseApiFactory, RouterFactoryResult } from '../types.js';
|
|
5
|
+
export declare const apiRouterFactory: <Context extends Record<string, unknown>>(context: Context, apiFactories: readonly BaseApiFactory<Context>[]) => RouterFactoryResult;
|
package/dist/http/mcp.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
2
2
|
import type { McpFeatureFlags, RouterFactoryResult } from '../types.js';
|
|
3
3
|
export declare const mcpRouterFactory: <Context extends Record<string, unknown>>(context: Context, createServer: (context: Context, featureFlags: McpFeatureFlags) => {
|
|
4
4
|
server: McpServer;
|
|
5
|
-
}, { name, stateful, }?: {
|
|
5
|
+
}, { name, stateful, inspector, }?: {
|
|
6
6
|
name?: string;
|
|
7
7
|
stateful?: boolean;
|
|
8
|
+
inspector?: boolean;
|
|
8
9
|
}) => RouterFactoryResult;
|
package/dist/http/mcp.js
CHANGED
|
@@ -8,7 +8,7 @@ import getRawBody from 'raw-body';
|
|
|
8
8
|
import { log } from '../logger.js';
|
|
9
9
|
const name = process.env.OTEL_SERVICE_NAME;
|
|
10
10
|
const tracer = trace.getTracer(name ? `${name}.router.mcp` : 'router.mcp');
|
|
11
|
-
export const mcpRouterFactory = (context, createServer, { name, stateful = true, } = {}) => {
|
|
11
|
+
export const mcpRouterFactory = (context, createServer, { name, stateful = true, inspector = false, } = {}) => {
|
|
12
12
|
const router = Router();
|
|
13
13
|
const transports = new Map();
|
|
14
14
|
const sessionFeatureFlags = new Map();
|
|
@@ -198,7 +198,11 @@ export const mcpRouterFactory = (context, createServer, { name, stateful = true,
|
|
|
198
198
|
<h1>${name}</h1>
|
|
199
199
|
<h2>Model Context Protocol (MCP) Server</h2>
|
|
200
200
|
<p>This endpoint is used for MCP communication. Please use an MCP-compatible client to interact with this server.</p>
|
|
201
|
-
|
|
201
|
+
${inspector
|
|
202
|
+
? `
|
|
203
|
+
<h3>Inspector</h3>
|
|
204
|
+
<p>You can use the <a href="/inspector">MCP Inspector</a> for testing purposes.</p>`
|
|
205
|
+
: ''}
|
|
202
206
|
<h3>Claude Code</h3>
|
|
203
207
|
<p>To connect to this MCP server using Claude Code, run the following command in your terminal:</p>
|
|
204
208
|
<pre><code>claude mcp add --transport http ${name || req.get('host')} ${fullUrl}</code></pre>
|
package/dist/httpServer.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { Server } from 'node:http';
|
|
3
3
|
import express from 'express';
|
|
4
|
-
import type { ZodRawShape } from 'zod';
|
|
5
4
|
import { type AdditionalSetupArgs } from './mcpServer.js';
|
|
6
|
-
import type {
|
|
5
|
+
import type { BaseApiFactory, BasePromptFactory, ResourceFactory } from './types.js';
|
|
7
6
|
export declare const httpServerFactory: <Context extends Record<string, unknown>>({ name, version, context, apiFactories, promptFactories, resourceFactories, additionalSetup, cleanupFn, stateful, instructions, }: {
|
|
8
7
|
name: string;
|
|
9
8
|
version?: string;
|
|
10
9
|
context: Context;
|
|
11
|
-
apiFactories?: readonly
|
|
12
|
-
promptFactories?: readonly
|
|
10
|
+
apiFactories?: readonly BaseApiFactory<Context>[];
|
|
11
|
+
promptFactories?: readonly BasePromptFactory<Context>[];
|
|
13
12
|
resourceFactories?: readonly ResourceFactory<Context>[];
|
|
14
13
|
additionalSetup?: (args: AdditionalSetupArgs<Context>) => void;
|
|
15
14
|
cleanupFn?: () => void | Promise<void>;
|
package/dist/httpServer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import bodyParser from 'body-parser';
|
|
2
3
|
import express from 'express';
|
|
3
4
|
import { apiRouterFactory } from './http/api.js';
|
|
4
5
|
import { mcpRouterFactory } from './http/mcp.js';
|
|
@@ -14,6 +15,9 @@ export const httpServerFactory = ({ name, version, context, apiFactories = [], p
|
|
|
14
15
|
log.info('Starting HTTP server...');
|
|
15
16
|
const app = express();
|
|
16
17
|
app.enable('trust proxy');
|
|
18
|
+
const PORT = process.env.PORT || 3001;
|
|
19
|
+
const inspector = process.env.NODE_ENV !== 'production' ||
|
|
20
|
+
['1', 'true'].includes(process.env.ENABLE_INSPECTOR ?? '0');
|
|
17
21
|
const [mcpRouter, mcpCleanup] = mcpRouterFactory(context, (context, featureFlags) => mcpServerFactory({
|
|
18
22
|
name,
|
|
19
23
|
version,
|
|
@@ -24,7 +28,7 @@ export const httpServerFactory = ({ name, version, context, apiFactories = [], p
|
|
|
24
28
|
additionalSetup,
|
|
25
29
|
featureFlags,
|
|
26
30
|
instructions,
|
|
27
|
-
}), { name, stateful });
|
|
31
|
+
}), { name, stateful, inspector });
|
|
28
32
|
cleanupFns.push(mcpCleanup);
|
|
29
33
|
app.use('/mcp', mcpRouter);
|
|
30
34
|
const [apiRouter, apiCleanup] = apiRouterFactory(context, apiFactories);
|
|
@@ -45,15 +49,26 @@ export const httpServerFactory = ({ name, version, context, apiFactories = [], p
|
|
|
45
49
|
.status(err instanceof StatusError ? err.status : 500)
|
|
46
50
|
.json({ error: err.message });
|
|
47
51
|
});
|
|
52
|
+
if (inspector) {
|
|
53
|
+
process.env.MCP_USE_ANONYMIZED_TELEMETRY = 'false';
|
|
54
|
+
import('@mcp-use/inspector')
|
|
55
|
+
.then(({ mountInspector }) => {
|
|
56
|
+
app.use(bodyParser.json());
|
|
57
|
+
mountInspector(app, { autoConnectUrl: `http://localhost:${PORT}/mcp` });
|
|
58
|
+
})
|
|
59
|
+
.catch(log.error);
|
|
60
|
+
}
|
|
48
61
|
// Start the server
|
|
49
|
-
const
|
|
50
|
-
const server = app.listen(PORT, (error) => {
|
|
62
|
+
const server = app.listen(PORT, async (error) => {
|
|
51
63
|
if (error) {
|
|
52
64
|
log.error('Error starting HTTP server:', error);
|
|
53
65
|
exitHandler(1);
|
|
54
66
|
}
|
|
55
67
|
else {
|
|
56
68
|
log.info(`HTTP Server listening on port ${PORT}`);
|
|
69
|
+
if (inspector) {
|
|
70
|
+
log.info(`🌐 MCP inspector running at http://localhost:${PORT}/inspector`);
|
|
71
|
+
}
|
|
57
72
|
}
|
|
58
73
|
});
|
|
59
74
|
cleanupFns.push(async () => {
|
package/dist/mcpServer.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import type { ServerCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type { ApiFactory, McpFeatureFlags, PromptFactory, ResourceFactory } from './types.js';
|
|
3
|
+
import type { BaseApiFactory, BasePromptFactory, McpFeatureFlags, ResourceFactory } from './types.js';
|
|
5
4
|
export interface AdditionalSetupArgs<Context extends Record<string, unknown>> {
|
|
6
5
|
context: Context;
|
|
7
6
|
server: McpServer;
|
|
@@ -11,8 +10,8 @@ export declare const mcpServerFactory: <Context extends Record<string, unknown>>
|
|
|
11
10
|
name: string;
|
|
12
11
|
version?: string;
|
|
13
12
|
context: Context;
|
|
14
|
-
apiFactories?: readonly
|
|
15
|
-
promptFactories?: readonly
|
|
13
|
+
apiFactories?: readonly BaseApiFactory<Context>[];
|
|
14
|
+
promptFactories?: readonly BasePromptFactory<Context>[];
|
|
16
15
|
resourceFactories?: readonly ResourceFactory<Context>[];
|
|
17
16
|
additionalSetup?: (args: AdditionalSetupArgs<Context>) => void;
|
|
18
17
|
additionalCapabilities?: ServerCapabilities;
|
package/dist/mcpServer.js
CHANGED
|
@@ -59,7 +59,7 @@ export const mcpServerFactory = ({ name, version = '1.0.0', context, apiFactorie
|
|
|
59
59
|
// make sense.
|
|
60
60
|
title: tool.config.title,
|
|
61
61
|
},
|
|
62
|
-
}, async (args, extra) => {
|
|
62
|
+
}, (async (args, extra) => {
|
|
63
63
|
let traceContext = otelContext.active();
|
|
64
64
|
if (extra?._meta?.traceparent) {
|
|
65
65
|
// Some MCP clients (e.g. pydantic) pass the parent trace context
|
|
@@ -106,7 +106,7 @@ export const mcpServerFactory = ({ name, version = '1.0.0', context, apiFactorie
|
|
|
106
106
|
span.end();
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
-
});
|
|
109
|
+
}));
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
if (enablePrompts) {
|
package/dist/stdio.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type { ZodRawShape } from 'zod';
|
|
3
2
|
import { type AdditionalSetupArgs } from './mcpServer.js';
|
|
4
|
-
import type {
|
|
3
|
+
import type { BaseApiFactory, BasePromptFactory, ResourceFactory } from './types.js';
|
|
5
4
|
export declare const stdioServerFactory: <Context extends Record<string, unknown>>({ name, version, context, apiFactories, promptFactories, resourceFactories, additionalSetup, cleanupFn, instructions, }: {
|
|
6
5
|
name: string;
|
|
7
6
|
version?: string;
|
|
8
7
|
context: Context;
|
|
9
|
-
apiFactories?: readonly
|
|
10
|
-
promptFactories?: readonly
|
|
8
|
+
apiFactories?: readonly BaseApiFactory<Context>[];
|
|
9
|
+
promptFactories?: readonly BasePromptFactory<Context>[];
|
|
11
10
|
resourceFactories?: readonly ResourceFactory<Context>[];
|
|
12
11
|
additionalSetup?: (args: AdditionalSetupArgs<Context>) => void;
|
|
13
12
|
cleanupFn?: () => Promise<void>;
|
package/dist/types.d.ts
CHANGED
|
@@ -2,21 +2,46 @@ import type { CompleteResourceTemplateCallback, ListResourcesCallback, ReadResou
|
|
|
2
2
|
import type { GetPromptResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
import type { Router } from 'express';
|
|
4
4
|
import type { ZodRawShape, ZodTypeAny, z } from 'zod';
|
|
5
|
-
export type
|
|
5
|
+
export type BaseToolConfig = {
|
|
6
6
|
title?: string;
|
|
7
7
|
description?: string;
|
|
8
|
-
inputSchema:
|
|
9
|
-
outputSchema:
|
|
8
|
+
inputSchema: ZodRawShape;
|
|
9
|
+
outputSchema: ZodRawShape;
|
|
10
10
|
annotations?: ToolAnnotations;
|
|
11
11
|
};
|
|
12
|
-
export interface
|
|
12
|
+
export interface BaseApiDefinition {
|
|
13
13
|
name: string;
|
|
14
14
|
method?: 'get' | 'post' | 'put' | 'delete';
|
|
15
15
|
route?: string | string[];
|
|
16
|
-
config:
|
|
16
|
+
config: BaseToolConfig;
|
|
17
17
|
disabled?: boolean;
|
|
18
|
-
fn
|
|
19
|
-
pickResult
|
|
18
|
+
fn(args: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
19
|
+
pickResult?(result: Record<string, unknown>): unknown;
|
|
20
|
+
}
|
|
21
|
+
export type BaseApiFactory<Context extends Record<string, unknown>> = (ctx: Context, featureFlags: McpFeatureFlags) => BaseApiDefinition;
|
|
22
|
+
export type BasePromptConfig = {
|
|
23
|
+
title?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
inputSchema: ZodRawShape;
|
|
26
|
+
};
|
|
27
|
+
export interface BasePromptDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
config: BasePromptConfig;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
fn(args: Record<string, unknown>): Promise<GetPromptResult>;
|
|
32
|
+
}
|
|
33
|
+
export type BasePromptFactory<Context extends Record<string, unknown>> = (ctx: Context, featureFlags: McpFeatureFlags) => BasePromptDefinition;
|
|
34
|
+
export type ToolConfig<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape> = {
|
|
35
|
+
title?: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
inputSchema: InputArgs;
|
|
38
|
+
outputSchema: OutputArgs;
|
|
39
|
+
annotations?: ToolAnnotations;
|
|
40
|
+
};
|
|
41
|
+
export interface ApiDefinition<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape, SimplifiedOutputArgs = OutputArgs> extends BaseApiDefinition {
|
|
42
|
+
config: ToolConfig<InputArgs, OutputArgs>;
|
|
43
|
+
fn(args: z.objectOutputType<InputArgs, ZodTypeAny>): Promise<z.objectOutputType<OutputArgs, ZodTypeAny>>;
|
|
44
|
+
pickResult?(result: z.objectOutputType<OutputArgs, ZodTypeAny>): SimplifiedOutputArgs;
|
|
20
45
|
}
|
|
21
46
|
export type ApiFactory<Context extends Record<string, unknown>, Input extends ZodRawShape, Output extends ZodRawShape, RestOutput = Output> = (ctx: Context, featureFlags: McpFeatureFlags) => ApiDefinition<Input, Output, RestOutput>;
|
|
22
47
|
export type RouterFactoryResult = [Router, () => void | Promise<void>];
|
|
@@ -25,11 +50,9 @@ export type PromptConfig<InputArgs extends ZodRawShape> = {
|
|
|
25
50
|
description?: string;
|
|
26
51
|
inputSchema: InputArgs;
|
|
27
52
|
};
|
|
28
|
-
export interface PromptDefinition<InputArgs extends ZodRawShape> {
|
|
29
|
-
name: string;
|
|
53
|
+
export interface PromptDefinition<InputArgs extends ZodRawShape> extends BasePromptDefinition {
|
|
30
54
|
config: PromptConfig<InputArgs>;
|
|
31
|
-
|
|
32
|
-
fn: (args: z.objectOutputType<InputArgs, ZodTypeAny>) => Promise<GetPromptResult>;
|
|
55
|
+
fn(args: z.objectOutputType<InputArgs, ZodTypeAny>): Promise<GetPromptResult>;
|
|
33
56
|
}
|
|
34
57
|
export type PromptFactory<Context extends Record<string, unknown>, Input extends ZodRawShape> = (ctx: Context, featureFlags: McpFeatureFlags) => PromptDefinition<Input>;
|
|
35
58
|
export interface TemplatedResourceDefinition {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tigerdata/mcp-boilerplate",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "MCP boilerplate code for Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "TigerData",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc",
|
|
34
|
-
"
|
|
34
|
+
"prepublishOnly": "tsc",
|
|
35
35
|
"watch": "tsc --watch",
|
|
36
36
|
"lint": "./bun x @biomejs/biome check"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@mcp-use/inspector": "^0.13.2",
|
|
39
40
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
40
41
|
"@opentelemetry/api": "^1.9.0",
|
|
41
42
|
"@opentelemetry/auto-instrumentations-node": "^0.67.3",
|