xmcp 1.1.3 → 1.3.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/dist/cloudflare.d.ts +1 -0
- package/dist/cloudflare.js +2 -2
- package/dist/config/index.d.ts +35 -35
- package/dist/config/schemas/experimental/index.d.ts +4 -4
- package/dist/config.js +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +13 -13
- package/dist/node.d.ts +55 -0
- package/dist/node.js +1 -0
- package/dist/runtime/adapter-express.js +24 -22
- package/dist/runtime/adapter-fastify.js +24 -22
- package/dist/runtime/adapter-nestjs.js +24 -22
- package/dist/runtime/adapter-nextjs.js +24 -22
- package/dist/runtime/adapter-tanstack-cloudflare.js +240 -0
- package/dist/runtime/adapter-tanstack.js +244 -0
- package/dist/runtime/cloudflare-worker.js +32 -30
- package/dist/runtime/contexts/request-context.d.ts +24 -0
- package/dist/runtime/headers.js +1 -1
- package/dist/runtime/http.js +46 -44
- package/dist/runtime/stdio.js +19 -17
- package/dist/runtime/utils/content.d.ts +7 -0
- package/dist/runtime/utils/mcp-middleware.d.ts +14 -0
- package/dist/runtime/utils/server.d.ts +2 -1
- package/dist/runtime/utils/tools.d.ts +2 -1
- package/dist/runtime/utils/transformers/prompt.d.ts +7 -5
- package/dist/runtime/utils/transformers/tool.d.ts +1 -0
- package/dist/runtime/vercel.js +46 -44
- package/dist/types/declarations.d.ts +3 -0
- package/dist/types/mcp-middleware.d.ts +17 -0
- package/dist/types/prompt.d.ts +1 -0
- package/dist/types/resource.d.ts +3 -0
- package/dist/utils/context.d.ts +3 -1
- package/package.json +9 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AudioContent, EmbeddedResource, ImageContent } from "@modelcontextprotocol/server";
|
|
2
|
+
/** Create an MCP image content block from raw bytes. */
|
|
3
|
+
export declare function image(bytes: Uint8Array | ArrayBuffer, mimeType: string): ImageContent;
|
|
4
|
+
/** Create an MCP audio content block from raw bytes. */
|
|
5
|
+
export declare function audio(bytes: Uint8Array | ArrayBuffer, mimeType: string): AudioContent;
|
|
6
|
+
/** Embed text or binary resource contents without registering a resource. */
|
|
7
|
+
export declare function embeddedResource(uri: string, content: string | Uint8Array | ArrayBuffer, mimeType?: string): EmbeddedResource;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { McpMiddleware } from "@/types/mcp-middleware";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
3
|
+
import { type McpToolHandler } from "./transformers/tool";
|
|
4
|
+
export declare function normalizeMcpMiddleware(value: unknown): McpMiddleware[];
|
|
5
|
+
/** Tool middleware stays inside SDK input/output validation and tool-error handling. */
|
|
6
|
+
export declare function wrapToolWithMiddleware(handler: McpToolHandler, name: string, middleware: readonly McpMiddleware[]): McpToolHandler;
|
|
7
|
+
/**
|
|
8
|
+
* McpServer installs listing/completion handlers lazily during registration and
|
|
9
|
+
* has no public handler getter. Decorate that public registration seam only
|
|
10
|
+
* while registering components, then restore it even if registration fails.
|
|
11
|
+
* This retains SDK catalog/URI/completion behavior and runs the chain once,
|
|
12
|
+
* including ResourceTemplate list/read/complete callbacks and generated UI resources.
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerWithMcpMiddleware(server: McpServer, middleware: readonly McpMiddleware[], register: () => void): void;
|
|
@@ -6,7 +6,7 @@ import { UserToolHandler } from "./transformers/tool";
|
|
|
6
6
|
import { UserPromptHandler } from "./transformers/prompt";
|
|
7
7
|
import { UserResourceHandler } from "./transformers/resource";
|
|
8
8
|
import { ZodRawShape } from "zod/v3";
|
|
9
|
-
import { ResourceMetadata } from "@/types/resource";
|
|
9
|
+
import { ResourceMetadata, ResourceCompletions } from "@/types/resource";
|
|
10
10
|
export type ToolFile = {
|
|
11
11
|
metadata: ToolMetadata;
|
|
12
12
|
schema: ZodRawShape;
|
|
@@ -21,6 +21,7 @@ export type PromptFile = {
|
|
|
21
21
|
export type ResourceFile = {
|
|
22
22
|
metadata: ResourceMetadata;
|
|
23
23
|
schema: ZodRawShape;
|
|
24
|
+
complete?: ResourceCompletions;
|
|
24
25
|
default: UserResourceHandler;
|
|
25
26
|
};
|
|
26
27
|
export declare const injectedTools: Record<string, () => Promise<ToolFile>>;
|
|
@@ -2,10 +2,11 @@ import { McpServer } from "@modelcontextprotocol/server";
|
|
|
2
2
|
import { ZodRawShape } from "zod/v3";
|
|
3
3
|
import { ToolFile } from "./server";
|
|
4
4
|
import { ToolMetadata } from "@/types/tool";
|
|
5
|
+
import type { McpMiddleware } from "@/types/mcp-middleware";
|
|
5
6
|
/** Validates if a value is a valid Zod schema object */
|
|
6
7
|
export declare function isZodRawShape(value: unknown): value is ZodRawShape;
|
|
7
8
|
export declare function pathToName(path: string): string;
|
|
8
9
|
/** Ensures toolConfig has its own annotations object with a title */
|
|
9
10
|
export declare function ensureAnnotations(toolConfig: Pick<ToolMetadata, "name" | "annotations">): void;
|
|
10
11
|
/** Loads tools and injects them into the server */
|
|
11
|
-
export declare function addToolsToServer(server: McpServer, toolModules: Map<string, ToolFile
|
|
12
|
+
export declare function addToolsToServer(server: McpServer, toolModules: Map<string, ToolFile>, middleware?: readonly McpMiddleware[]): McpServer;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { GetPromptResult, ServerContext } from "@modelcontextprotocol/server";
|
|
1
|
+
import { type GetPromptResult, type PromptMessage, type ServerContext } from "@modelcontextprotocol/server";
|
|
2
2
|
import { PromptArgsRawShape } from "../prompts";
|
|
3
3
|
/**
|
|
4
4
|
* Type for content that users can return from prompt handlers
|
|
5
5
|
*/
|
|
6
6
|
export type PromptContent = GetPromptResult["messages"][number]["content"];
|
|
7
|
+
type UserPromptResult = PromptContent | string | number | GetPromptResult | PromptMessage[];
|
|
7
8
|
/**
|
|
8
9
|
* Type for the original prompt handler that users write
|
|
9
10
|
* The extra parameter is optional for backward compatibility
|
|
10
|
-
*
|
|
11
|
+
* Supports single content values, message arrays, and full prompt results.
|
|
11
12
|
*/
|
|
12
|
-
export type UserPromptHandler = (args: PromptArgsRawShape, extra?: ServerContext) =>
|
|
13
|
+
export type UserPromptHandler = (args: PromptArgsRawShape, extra?: ServerContext) => UserPromptResult | Promise<UserPromptResult>;
|
|
13
14
|
/**
|
|
14
15
|
* Type for the transformed handler that the MCP server expects
|
|
15
16
|
*/
|
|
@@ -20,12 +21,13 @@ export type McpPromptHandler = (args: PromptArgsRawShape, extra: ServerContext)
|
|
|
20
21
|
* This function:
|
|
21
22
|
* 1. Passes through both args and extra parameters to the user's handler
|
|
22
23
|
* 2. Transforms string/number/content responses into a single message GetPromptResult format
|
|
23
|
-
* 3.
|
|
24
|
+
* 3. Preserves explicit message roles and full result metadata
|
|
24
25
|
* 4. Validates that the response is valid and throws a descriptive error if not
|
|
25
26
|
*
|
|
26
27
|
* @param handler - The user's prompt handler function
|
|
27
|
-
* @param role - The role
|
|
28
|
+
* @param role - The role for single content values ("user" or "assistant")
|
|
28
29
|
* @returns A transformed handler compatible with McpServer.registerPrompt
|
|
29
30
|
* @throws Error if the handler returns an invalid response type
|
|
30
31
|
*/
|
|
31
32
|
export declare function transformPromptHandler(handler: UserPromptHandler, role?: "user" | "assistant"): McpPromptHandler;
|
|
33
|
+
export {};
|
|
@@ -10,6 +10,7 @@ export type UserToolHandler = (args: ZodRawShape, extra: ToolExtraArguments) =>
|
|
|
10
10
|
* Type for the transformed handler that the MCP server expects
|
|
11
11
|
*/
|
|
12
12
|
export type McpToolHandler = (args: ZodRawShape, ctx: ServerContext) => CallToolResult | InputRequiredResult | Promise<CallToolResult | InputRequiredResult>;
|
|
13
|
+
export declare function resolveToolClientInfo(ctx: ServerContext): ToolExtraArguments["clientInfo"];
|
|
13
14
|
/**
|
|
14
15
|
* Transforms a user's tool handler into an MCP-compatible handler.
|
|
15
16
|
*
|