mcp-ts-template 1.6.3 → 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/README.md +4 -4
- package/dist/mcp-server/resources/echoResource/registration.js +2 -3
- package/dist/mcp-server/tools/catFactFetcher/logic.d.ts +18 -4
- package/dist/mcp-server/tools/catFactFetcher/logic.js +16 -0
- package/dist/mcp-server/tools/catFactFetcher/registration.js +22 -21
- package/dist/mcp-server/tools/echoTool/logic.d.ts +23 -11
- package/dist/mcp-server/tools/echoTool/logic.js +30 -2
- package/dist/mcp-server/tools/echoTool/registration.js +22 -21
- package/dist/mcp-server/tools/imageTest/logic.d.ts +9 -2
- package/dist/mcp-server/tools/imageTest/logic.js +4 -0
- package/dist/mcp-server/tools/imageTest/registration.js +21 -26
- package/package.json +17 -15
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# 🚀 MCP TypeScript Template: Agent, Server & Client
|
|
2
2
|
|
|
3
3
|
[](https://www.typescriptlang.org/)
|
|
4
|
-
[](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
5
|
+
[](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-06-18/changelog.mdx)
|
|
6
|
+
[](./CHANGELOG.md)
|
|
7
7
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
8
8
|
[](https://github.com/cyanheads/mcp-ts-template/issues)
|
|
9
9
|
[](https://github.com/cyanheads/mcp-ts-template)
|
|
10
10
|
|
|
11
11
|
**Jumpstart your [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) development with this comprehensive TypeScript Template for building autonomous agents, servers, and clients.**
|
|
12
12
|
|
|
13
|
-
This template provides a solid, beginner-friendly foundation for building all components of the MCP ecosystem, adhering to the **MCP 2025-
|
|
13
|
+
This template provides a solid, beginner-friendly foundation for building all components of the MCP ecosystem, adhering to the **MCP 2025-06-18 specification**. It includes a powerful agent framework, a fully-featured server, a robust client, production-ready utilities, and clear documentation to get you up and running quickly.
|
|
14
14
|
|
|
15
15
|
## 🏛️ Three-Part Architecture
|
|
16
16
|
|
|
@@ -60,13 +60,12 @@ export const registerEchoResource = async (server) => {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
|
-
|
|
63
|
+
// Re-throw to be caught by the SDK's top-level error handler
|
|
64
|
+
throw ErrorHandler.handleError(error, {
|
|
64
65
|
operation: "echoResourceReadHandler",
|
|
65
66
|
context: handlerContext,
|
|
66
67
|
input: { uri: uri.href, params },
|
|
67
68
|
});
|
|
68
|
-
// Re-throw to be caught by the SDK's top-level error handler
|
|
69
|
-
throw handledError;
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
71
|
logger.info(`Resource '${resourceName}' registered successfully.`, registrationContext);
|
|
@@ -20,14 +20,28 @@ export declare const CatFactFetcherInputSchema: z.ZodObject<{
|
|
|
20
20
|
*/
|
|
21
21
|
export type CatFactFetcherInput = z.infer<typeof CatFactFetcherInputSchema>;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Zod schema for the successful response of the `get_random_cat_fact` tool.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export declare const CatFactFetcherResponseSchema: z.ZodObject<{
|
|
26
|
+
fact: z.ZodString;
|
|
27
|
+
length: z.ZodNumber;
|
|
28
|
+
requestedMaxLength: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
timestamp: z.ZodString;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
length: number;
|
|
32
|
+
timestamp: string;
|
|
26
33
|
fact: string;
|
|
34
|
+
requestedMaxLength?: number | undefined;
|
|
35
|
+
}, {
|
|
27
36
|
length: number;
|
|
28
|
-
requestedMaxLength?: number;
|
|
29
37
|
timestamp: string;
|
|
30
|
-
|
|
38
|
+
fact: string;
|
|
39
|
+
requestedMaxLength?: number | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Defines the structure of the JSON payload returned by the `get_random_cat_fact` tool handler.
|
|
43
|
+
*/
|
|
44
|
+
export type CatFactFetcherResponse = z.infer<typeof CatFactFetcherResponseSchema>;
|
|
31
45
|
/**
|
|
32
46
|
* Processes the core logic for the `get_random_cat_fact` tool.
|
|
33
47
|
* It calls the Cat Fact Ninja API and returns the fetched fact.
|
|
@@ -19,6 +19,22 @@ export const CatFactFetcherInputSchema = z
|
|
|
19
19
|
.describe("Optional: The maximum character length of the cat fact to retrieve."),
|
|
20
20
|
})
|
|
21
21
|
.describe("Input schema for the get_random_cat_fact tool. Allows specifying a maximum length for the fact.");
|
|
22
|
+
/**
|
|
23
|
+
* Zod schema for the successful response of the `get_random_cat_fact` tool.
|
|
24
|
+
*/
|
|
25
|
+
export const CatFactFetcherResponseSchema = z.object({
|
|
26
|
+
fact: z.string().describe("The retrieved cat fact."),
|
|
27
|
+
length: z.number().int().describe("The character length of the cat fact."),
|
|
28
|
+
requestedMaxLength: z
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("The maximum length that was requested for the fact."),
|
|
33
|
+
timestamp: z
|
|
34
|
+
.string()
|
|
35
|
+
.datetime()
|
|
36
|
+
.describe("ISO 8601 timestamp of when the response was generated."),
|
|
37
|
+
});
|
|
22
38
|
/**
|
|
23
39
|
* Processes the core logic for the `get_random_cat_fact` tool.
|
|
24
40
|
* It calls the Cat Fact Ninja API and returns the fetched fact.
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Cat Fact Ninja API.
|
|
5
5
|
* @module src/mcp-server/tools/catFactFetcher/registration
|
|
6
6
|
*/
|
|
7
|
-
import { BaseErrorCode
|
|
7
|
+
import { BaseErrorCode } from "../../../types-global/errors.js";
|
|
8
8
|
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
9
|
-
import { CatFactFetcherInputSchema, catFactFetcherLogic, } from "./logic.js";
|
|
9
|
+
import { CatFactFetcherInputSchema, catFactFetcherLogic, CatFactFetcherResponseSchema, } from "./logic.js";
|
|
10
10
|
/**
|
|
11
11
|
* Registers the 'get_random_cat_fact' tool and its handler with the MCP server.
|
|
12
12
|
*
|
|
@@ -22,46 +22,47 @@ export const registerCatFactFetcherTool = async (server) => {
|
|
|
22
22
|
});
|
|
23
23
|
logger.info(`Registering tool: '${toolName}'`, registrationContext);
|
|
24
24
|
await ErrorHandler.tryCatch(async () => {
|
|
25
|
-
server.
|
|
25
|
+
server.registerTool(toolName, {
|
|
26
|
+
title: "Get Random Cat Fact",
|
|
27
|
+
description: toolDescription,
|
|
28
|
+
inputSchema: CatFactFetcherInputSchema.shape,
|
|
29
|
+
outputSchema: CatFactFetcherResponseSchema.shape,
|
|
30
|
+
annotations: {
|
|
31
|
+
readOnlyHint: true,
|
|
32
|
+
openWorldHint: true,
|
|
33
|
+
},
|
|
34
|
+
}, async (params) => {
|
|
26
35
|
const handlerContext = requestContextService.createRequestContext({
|
|
27
36
|
parentRequestId: registrationContext.requestId,
|
|
28
37
|
operation: "HandleToolRequest",
|
|
29
38
|
toolName: toolName,
|
|
30
|
-
mcpToolContext: mcpContext,
|
|
31
39
|
input: params,
|
|
32
40
|
});
|
|
33
41
|
try {
|
|
34
42
|
const result = await catFactFetcherLogic(params, handlerContext);
|
|
43
|
+
// Return both structuredContent for modern clients and
|
|
44
|
+
// stringified content for backward compatibility.
|
|
35
45
|
return {
|
|
46
|
+
structuredContent: result,
|
|
36
47
|
content: [
|
|
37
48
|
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
38
49
|
],
|
|
39
|
-
isError: false,
|
|
40
50
|
};
|
|
41
51
|
}
|
|
42
52
|
catch (error) {
|
|
43
|
-
const
|
|
53
|
+
const mcpError = ErrorHandler.handleError(error, {
|
|
44
54
|
operation: "catFactFetcherToolHandler",
|
|
45
55
|
context: handlerContext,
|
|
46
56
|
input: params,
|
|
47
57
|
});
|
|
48
|
-
const mcpError = handledError instanceof McpError
|
|
49
|
-
? handledError
|
|
50
|
-
: new McpError(BaseErrorCode.INTERNAL_ERROR, "An unexpected error occurred while fetching a cat fact.", { originalErrorName: handledError.name });
|
|
51
58
|
return {
|
|
52
|
-
content: [
|
|
53
|
-
{
|
|
54
|
-
type: "text",
|
|
55
|
-
text: JSON.stringify({
|
|
56
|
-
error: {
|
|
57
|
-
code: mcpError.code,
|
|
58
|
-
message: mcpError.message,
|
|
59
|
-
details: mcpError.details,
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
59
|
isError: true,
|
|
60
|
+
content: [{ type: "text", text: `Error: ${mcpError.message}` }],
|
|
61
|
+
structuredContent: {
|
|
62
|
+
code: mcpError.code,
|
|
63
|
+
message: mcpError.message,
|
|
64
|
+
details: mcpError.details,
|
|
65
|
+
},
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
});
|
|
@@ -36,22 +36,34 @@ export declare const EchoToolInputSchema: z.ZodObject<{
|
|
|
36
36
|
*/
|
|
37
37
|
export type EchoToolInput = z.infer<typeof EchoToolInputSchema>;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Zod schema for the successful response of the `echo_message` tool.
|
|
40
40
|
*/
|
|
41
|
-
export
|
|
42
|
-
|
|
41
|
+
export declare const EchoToolResponseSchema: z.ZodObject<{
|
|
42
|
+
originalMessage: z.ZodString;
|
|
43
|
+
formattedMessage: z.ZodString;
|
|
44
|
+
repeatedMessage: z.ZodString;
|
|
45
|
+
mode: z.ZodEnum<["standard", "uppercase", "lowercase"]>;
|
|
46
|
+
repeatCount: z.ZodNumber;
|
|
47
|
+
timestamp: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
49
|
originalMessage: string;
|
|
44
|
-
|
|
50
|
+
mode: "standard" | "uppercase" | "lowercase";
|
|
45
51
|
formattedMessage: string;
|
|
46
|
-
/** The formatted message repeated the specified number of times, joined by spaces. */
|
|
47
52
|
repeatedMessage: string;
|
|
48
|
-
/** The formatting mode that was applied. */
|
|
49
|
-
mode: (typeof ECHO_MODES)[number];
|
|
50
|
-
/** The number of times the message was repeated. */
|
|
51
53
|
repeatCount: number;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
timestamp?: string | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
originalMessage: string;
|
|
57
|
+
mode: "standard" | "uppercase" | "lowercase";
|
|
58
|
+
formattedMessage: string;
|
|
59
|
+
repeatedMessage: string;
|
|
60
|
+
repeatCount: number;
|
|
61
|
+
timestamp?: string | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Defines the structure of the JSON payload returned by the `echo_message` tool.
|
|
65
|
+
*/
|
|
66
|
+
export type EchoToolResponse = z.infer<typeof EchoToolResponseSchema>;
|
|
55
67
|
/**
|
|
56
68
|
* Processes the core logic for the `echo_message` tool.
|
|
57
69
|
* It takes validated input parameters, formats the message according to the specified mode,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { logger } from "../../../utils/index.js";
|
|
9
|
+
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
|
|
9
10
|
/**
|
|
10
11
|
* Defines the valid formatting modes for the echo tool operation.
|
|
11
12
|
*/
|
|
@@ -39,8 +40,32 @@ export const EchoToolInputSchema = z
|
|
|
39
40
|
.optional()
|
|
40
41
|
.default(true)
|
|
41
42
|
.describe("Whether to include an ISO 8601 timestamp in the response. Defaults to true."),
|
|
42
|
-
})
|
|
43
|
-
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Zod schema for the successful response of the `echo_message` tool.
|
|
46
|
+
*/
|
|
47
|
+
export const EchoToolResponseSchema = z.object({
|
|
48
|
+
originalMessage: z
|
|
49
|
+
.string()
|
|
50
|
+
.describe("The original message provided in the input."),
|
|
51
|
+
formattedMessage: z
|
|
52
|
+
.string()
|
|
53
|
+
.describe("The message after applying the specified formatting mode."),
|
|
54
|
+
repeatedMessage: z
|
|
55
|
+
.string()
|
|
56
|
+
.describe("The formatted message repeated the specified number of times, joined by spaces."),
|
|
57
|
+
mode: z.enum(ECHO_MODES).describe("The formatting mode that was applied."),
|
|
58
|
+
repeatCount: z
|
|
59
|
+
.number()
|
|
60
|
+
.int()
|
|
61
|
+
.min(1)
|
|
62
|
+
.describe("The number of times the message was repeated."),
|
|
63
|
+
timestamp: z
|
|
64
|
+
.string()
|
|
65
|
+
.datetime()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Optional ISO 8601 timestamp of when the response was generated."),
|
|
68
|
+
});
|
|
44
69
|
/**
|
|
45
70
|
* Processes the core logic for the `echo_message` tool.
|
|
46
71
|
* It takes validated input parameters, formats the message according to the specified mode,
|
|
@@ -55,6 +80,9 @@ export async function echoToolLogic(params, context) {
|
|
|
55
80
|
...context,
|
|
56
81
|
toolInput: params,
|
|
57
82
|
});
|
|
83
|
+
if (params.message === "fail") {
|
|
84
|
+
throw new McpError(BaseErrorCode.VALIDATION_ERROR, "The message was 'fail'.");
|
|
85
|
+
}
|
|
58
86
|
let formattedMessage = params.message;
|
|
59
87
|
switch (params.mode) {
|
|
60
88
|
case "uppercase":
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* and the asynchronous handler function that processes tool invocation requests.
|
|
5
5
|
* @module src/mcp-server/tools/echoTool/registration
|
|
6
6
|
*/
|
|
7
|
-
import { BaseErrorCode
|
|
7
|
+
import { BaseErrorCode } from "../../../types-global/errors.js";
|
|
8
8
|
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
9
|
-
import { EchoToolInputSchema, echoToolLogic } from "./logic.js";
|
|
9
|
+
import { EchoToolInputSchema, echoToolLogic, EchoToolResponseSchema, } from "./logic.js";
|
|
10
10
|
/**
|
|
11
11
|
* Registers the 'echo_message' tool and its handler with the provided MCP server instance.
|
|
12
12
|
*
|
|
@@ -22,46 +22,47 @@ export const registerEchoTool = async (server) => {
|
|
|
22
22
|
});
|
|
23
23
|
logger.info(`Registering tool: '${toolName}'`, registrationContext);
|
|
24
24
|
await ErrorHandler.tryCatch(async () => {
|
|
25
|
-
server.
|
|
25
|
+
server.registerTool(toolName, {
|
|
26
|
+
title: "Echo Message",
|
|
27
|
+
description: toolDescription,
|
|
28
|
+
inputSchema: EchoToolInputSchema.shape,
|
|
29
|
+
outputSchema: EchoToolResponseSchema.shape,
|
|
30
|
+
annotations: {
|
|
31
|
+
readOnlyHint: true,
|
|
32
|
+
openWorldHint: false,
|
|
33
|
+
},
|
|
34
|
+
}, async (params) => {
|
|
26
35
|
const handlerContext = requestContextService.createRequestContext({
|
|
27
36
|
parentRequestId: registrationContext.requestId,
|
|
28
37
|
operation: "HandleToolRequest",
|
|
29
38
|
toolName: toolName,
|
|
30
|
-
mcpToolContext: mcpContext,
|
|
31
39
|
input: params,
|
|
32
40
|
});
|
|
33
41
|
try {
|
|
34
42
|
const result = await echoToolLogic(params, handlerContext);
|
|
43
|
+
// Return both structuredContent for modern clients and
|
|
44
|
+
// stringified content for backward compatibility.
|
|
35
45
|
return {
|
|
46
|
+
structuredContent: result,
|
|
36
47
|
content: [
|
|
37
48
|
{ type: "text", text: JSON.stringify(result, null, 2) },
|
|
38
49
|
],
|
|
39
|
-
isError: false,
|
|
40
50
|
};
|
|
41
51
|
}
|
|
42
52
|
catch (error) {
|
|
43
|
-
const
|
|
53
|
+
const mcpError = ErrorHandler.handleError(error, {
|
|
44
54
|
operation: "echoToolHandler",
|
|
45
55
|
context: handlerContext,
|
|
46
56
|
input: params,
|
|
47
57
|
});
|
|
48
|
-
const mcpError = handledError instanceof McpError
|
|
49
|
-
? handledError
|
|
50
|
-
: new McpError(BaseErrorCode.INTERNAL_ERROR, "An unexpected error occurred in the echo tool.", { originalErrorName: handledError.name });
|
|
51
58
|
return {
|
|
52
|
-
content: [
|
|
53
|
-
{
|
|
54
|
-
type: "text",
|
|
55
|
-
text: JSON.stringify({
|
|
56
|
-
error: {
|
|
57
|
-
code: mcpError.code,
|
|
58
|
-
message: mcpError.message,
|
|
59
|
-
details: mcpError.details,
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
59
|
isError: true,
|
|
60
|
+
content: [{ type: "text", text: `Error: ${mcpError.message}` }],
|
|
61
|
+
structuredContent: {
|
|
62
|
+
code: mcpError.code,
|
|
63
|
+
message: mcpError.message,
|
|
64
|
+
details: mcpError.details,
|
|
65
|
+
},
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
});
|
|
@@ -12,8 +12,15 @@ export declare const FetchImageTestInputSchema: z.ZodObject<{
|
|
|
12
12
|
trigger?: boolean | undefined;
|
|
13
13
|
}>;
|
|
14
14
|
export type FetchImageTestInput = z.infer<typeof FetchImageTestInputSchema>;
|
|
15
|
-
export
|
|
15
|
+
export declare const FetchImageTestResponseSchema: z.ZodObject<{
|
|
16
|
+
data: z.ZodString;
|
|
17
|
+
mimeType: z.ZodString;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
mimeType: string;
|
|
16
20
|
data: string;
|
|
21
|
+
}, {
|
|
17
22
|
mimeType: string;
|
|
18
|
-
|
|
23
|
+
data: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type FetchImageTestResponse = z.infer<typeof FetchImageTestResponseSchema>;
|
|
19
26
|
export declare function fetchImageTestLogic(input: FetchImageTestInput, parentRequestContext: RequestContext): Promise<FetchImageTestResponse>;
|
|
@@ -12,6 +12,10 @@ export const FetchImageTestInputSchema = z.object({
|
|
|
12
12
|
.default(true)
|
|
13
13
|
.describe("A trigger to invoke the tool and fetch a new cat image."),
|
|
14
14
|
});
|
|
15
|
+
export const FetchImageTestResponseSchema = z.object({
|
|
16
|
+
data: z.string().describe("Base64 encoded image data."),
|
|
17
|
+
mimeType: z.string().describe("The MIME type of the image (e.g., 'image/jpeg')."),
|
|
18
|
+
});
|
|
15
19
|
const CAT_API_URL = "https://cataas.com/cat";
|
|
16
20
|
export async function fetchImageTestLogic(input, parentRequestContext) {
|
|
17
21
|
const operationContext = requestContextService.createRequestContext({
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @fileoverview Registration for the fetch_image_test MCP tool.
|
|
3
3
|
* @module src/mcp-server/tools/imageTest/registration
|
|
4
4
|
*/
|
|
5
|
-
import { BaseErrorCode
|
|
5
|
+
import { BaseErrorCode } from "../../../types-global/errors.js";
|
|
6
6
|
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
7
|
-
import { FetchImageTestInputSchema, fetchImageTestLogic, } from "./logic.js";
|
|
7
|
+
import { FetchImageTestInputSchema, fetchImageTestLogic, FetchImageTestResponseSchema, } from "./logic.js";
|
|
8
8
|
/**
|
|
9
9
|
* Registers the fetch_image_test tool with the MCP server.
|
|
10
10
|
* @param server - The McpServer instance.
|
|
@@ -17,14 +17,18 @@ export function registerFetchImageTestTool(server) {
|
|
|
17
17
|
operation,
|
|
18
18
|
});
|
|
19
19
|
ErrorHandler.tryCatch(async () => {
|
|
20
|
-
server.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
server.registerTool(toolName, {
|
|
21
|
+
title: "Fetch Cat Image",
|
|
22
|
+
description: toolDescription,
|
|
23
|
+
inputSchema: FetchImageTestInputSchema.shape,
|
|
24
|
+
outputSchema: FetchImageTestResponseSchema.shape,
|
|
25
|
+
annotations: {
|
|
26
|
+
readOnlyHint: true,
|
|
27
|
+
openWorldHint: true,
|
|
28
|
+
},
|
|
29
|
+
}, async (input) => {
|
|
26
30
|
const handlerContext = requestContextService.createRequestContext({
|
|
27
|
-
parentRequestId,
|
|
31
|
+
parentRequestId: registrationContext.requestId,
|
|
28
32
|
operation: "fetchImageTestToolHandler",
|
|
29
33
|
toolName: toolName,
|
|
30
34
|
input,
|
|
@@ -32,6 +36,7 @@ export function registerFetchImageTestTool(server) {
|
|
|
32
36
|
try {
|
|
33
37
|
const result = await fetchImageTestLogic(input, handlerContext);
|
|
34
38
|
return {
|
|
39
|
+
structuredContent: result,
|
|
35
40
|
content: [
|
|
36
41
|
{
|
|
37
42
|
type: "image",
|
|
@@ -39,32 +44,22 @@ export function registerFetchImageTestTool(server) {
|
|
|
39
44
|
mimeType: result.mimeType,
|
|
40
45
|
},
|
|
41
46
|
],
|
|
42
|
-
isError: false,
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
49
|
catch (error) {
|
|
46
|
-
const
|
|
50
|
+
const mcpError = ErrorHandler.handleError(error, {
|
|
47
51
|
operation: "fetchImageTestToolHandler",
|
|
48
52
|
context: handlerContext,
|
|
49
53
|
input,
|
|
50
54
|
});
|
|
51
|
-
const mcpError = handledError instanceof McpError
|
|
52
|
-
? handledError
|
|
53
|
-
: new McpError(BaseErrorCode.INTERNAL_ERROR, "An unexpected error occurred while fetching the image.", { originalErrorName: handledError.name });
|
|
54
55
|
return {
|
|
55
|
-
content: [
|
|
56
|
-
{
|
|
57
|
-
type: "text",
|
|
58
|
-
text: JSON.stringify({
|
|
59
|
-
error: {
|
|
60
|
-
code: mcpError.code,
|
|
61
|
-
message: mcpError.message,
|
|
62
|
-
details: mcpError.details,
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
56
|
isError: true,
|
|
57
|
+
content: [{ type: "text", text: `Error: ${mcpError.message}` }],
|
|
58
|
+
structuredContent: {
|
|
59
|
+
code: mcpError.code,
|
|
60
|
+
message: mcpError.message,
|
|
61
|
+
details: mcpError.details,
|
|
62
|
+
},
|
|
68
63
|
};
|
|
69
64
|
}
|
|
70
65
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-ts-template",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Jumpstart Model Context Protocol (MCP) development with this production-ready TypeScript template. Build robust MCP servers and clients with built-in utilities, authentication, and service integrations. Agent framework utilizing MCP Client included.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -35,35 +35,37 @@
|
|
|
35
35
|
"fetch-spec": "ts-node --esm scripts/fetch-openapi-spec.ts",
|
|
36
36
|
"format": "prettier --write \"**/*.{ts,js,json,md,html,css}\"",
|
|
37
37
|
"inspector": "npx mcp-inspector --config mcp.json --server mcp-ts-template",
|
|
38
|
-
"db:duckdb-example": "MCP_LOG_LEVEL=debug tsc && node dist/storage/duckdbExample.js"
|
|
38
|
+
"db:duckdb-example": "MCP_LOG_LEVEL=debug tsc && node dist/storage/duckdbExample.js",
|
|
39
|
+
"test:perf": "ts-node scripts/performance-tester.ts",
|
|
40
|
+
"test:perf:batch": "ts-node scripts/performance-tester.ts --tool=echo_message --requests=100 --concurrency=10 --batchSize=10"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@duckdb/node-api": "^1.3.
|
|
42
|
-
"@hono/node-server": "^1.
|
|
43
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
44
|
-
"@supabase/supabase-js": "^2.
|
|
45
|
-
"@types/node": "^24.0.
|
|
43
|
+
"@duckdb/node-api": "^1.3.2-alpha.24",
|
|
44
|
+
"@hono/node-server": "^1.16.0",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.16.0",
|
|
46
|
+
"@supabase/supabase-js": "^2.52.0",
|
|
47
|
+
"@types/node": "^24.0.14",
|
|
46
48
|
"@types/sanitize-html": "^2.16.0",
|
|
47
49
|
"@types/validator": "13.15.2",
|
|
48
50
|
"chrono-node": "^2.8.0",
|
|
49
51
|
"dotenv": "^16.6.1",
|
|
50
|
-
"eslint": "^9.
|
|
51
|
-
"hono": "^4.8.
|
|
52
|
+
"eslint": "^9.31.0",
|
|
53
|
+
"hono": "^4.8.5",
|
|
52
54
|
"ignore": "^7.0.5",
|
|
53
|
-
"jose": "^6.0.
|
|
55
|
+
"jose": "^6.0.12",
|
|
54
56
|
"js-yaml": "^4.1.0",
|
|
55
|
-
"node-cron": "^4.2.
|
|
56
|
-
"openai": "^5.
|
|
57
|
+
"node-cron": "^4.2.1",
|
|
58
|
+
"openai": "^5.10.1",
|
|
57
59
|
"partial-json": "^0.1.7",
|
|
58
60
|
"sanitize-html": "^2.17.0",
|
|
59
61
|
"tiktoken": "^1.0.21",
|
|
60
62
|
"ts-node": "^10.9.2",
|
|
61
63
|
"typescript": "^5.8.3",
|
|
62
|
-
"typescript-eslint": "^8.
|
|
64
|
+
"typescript-eslint": "^8.37.0",
|
|
63
65
|
"validator": "13.15.15",
|
|
64
66
|
"winston": "^3.17.0",
|
|
65
67
|
"winston-transport": "^4.9.0",
|
|
66
|
-
"zod": "^3.25.
|
|
68
|
+
"zod": "^3.25.76"
|
|
67
69
|
},
|
|
68
70
|
"keywords": [
|
|
69
71
|
"typescript",
|
|
@@ -105,7 +107,7 @@
|
|
|
105
107
|
"node": ">=20.0.0"
|
|
106
108
|
},
|
|
107
109
|
"devDependencies": {
|
|
108
|
-
"@eslint/js": "^9.
|
|
110
|
+
"@eslint/js": "^9.31.0",
|
|
109
111
|
"@types/js-yaml": "^4.0.9",
|
|
110
112
|
"@types/node-cron": "^3.0.11",
|
|
111
113
|
"axios": "^1.10.0",
|