xmcp 1.1.3 → 1.2.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.
@@ -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;
@@ -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>): McpServer;
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
- * Users can only return content objects, strings, or numbers - not full message arrays
11
+ * Supports single content values, message arrays, and full prompt results.
11
12
  */
12
- export type UserPromptHandler = (args: PromptArgsRawShape, extra?: ServerContext) => PromptContent | string | number | Promise<PromptContent | string | number>;
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. Always creates exactly one message with the specified role
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 to assign to the message ("user" or "assistant")
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
  *