@outfitter/mcp 0.4.2 → 0.5.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.
Files changed (52) hide show
  1. package/README.md +130 -28
  2. package/dist/actions.d.ts +7 -2
  3. package/dist/actions.js +52 -5
  4. package/dist/core-tools.d.ts +7 -2
  5. package/dist/core-tools.js +140 -6
  6. package/dist/index.d.ts +14 -953
  7. package/dist/index.js +8 -959
  8. package/dist/internal/content-types.d.ts +2 -0
  9. package/dist/internal/content-types.js +1 -0
  10. package/dist/internal/log-config.d.ts +24 -0
  11. package/dist/internal/log-config.js +13 -0
  12. package/dist/internal/prompt-types.d.ts +3 -0
  13. package/dist/internal/prompt-types.js +1 -0
  14. package/dist/internal/resource-types.d.ts +4 -0
  15. package/dist/internal/resource-types.js +1 -0
  16. package/dist/internal/server-types.d.ts +7 -0
  17. package/dist/internal/server-types.js +20 -0
  18. package/dist/internal/tool-types.d.ts +2 -0
  19. package/dist/{shared/@outfitter/mcp-9m5hs2z0.js → internal/tool-types.js} +4 -16
  20. package/dist/internal/uri-template.d.ts +8 -0
  21. package/dist/internal/uri-template.js +7 -0
  22. package/dist/progress.d.ts +2 -0
  23. package/dist/progress.js +7 -0
  24. package/dist/schema.js +1 -1
  25. package/dist/server.d.ts +7 -2
  26. package/dist/server.js +6 -3
  27. package/dist/shared/@outfitter/{mcp-5b5726ga.d.ts → mcp-3hxaatj9.d.ts} +37 -6
  28. package/dist/shared/@outfitter/{mcp-zb3p61y9.d.ts → mcp-4s22693j.d.ts} +1 -1
  29. package/dist/shared/@outfitter/mcp-7btcghjj.d.ts +304 -0
  30. package/dist/shared/@outfitter/mcp-9ry52yg3.d.ts +187 -0
  31. package/dist/shared/@outfitter/mcp-dgwj3jna.d.ts +103 -0
  32. package/dist/shared/@outfitter/{mcp-5jcgb033.d.ts → mcp-f67dnr72.d.ts} +1 -1
  33. package/dist/shared/@outfitter/mcp-hw5wz4gb.js +1 -0
  34. package/dist/shared/@outfitter/mcp-knc1gq0g.d.ts +130 -0
  35. package/dist/shared/@outfitter/mcp-n9vzcp37.js +55 -0
  36. package/dist/shared/@outfitter/mcp-q5hr7227.d.ts +24 -0
  37. package/dist/shared/@outfitter/mcp-q70dtfj6.js +53 -0
  38. package/dist/shared/@outfitter/mcp-r27vbpc1.d.ts +45 -0
  39. package/dist/shared/@outfitter/mcp-s2vnhzav.js +2 -0
  40. package/dist/shared/@outfitter/{mcp-s3gfhcdk.d.ts → mcp-yf0w5cgh.d.ts} +1 -1
  41. package/dist/shared/@outfitter/{mcp-hh12tqfg.js → mcp-yf1n85e9.js} +79 -119
  42. package/dist/shared/@outfitter/mcp-zt2s3r38.js +33 -0
  43. package/dist/transport.d.ts +7 -2
  44. package/dist/transport.js +161 -5
  45. package/dist/types.d.ts +7 -2
  46. package/dist/types.js +1 -1
  47. package/package.json +33 -27
  48. package/dist/shared/@outfitter/mcp-fks4zt1z.d.ts +0 -699
  49. package/dist/shared/@outfitter/mcp-mzky3ck8.js +0 -165
  50. package/dist/shared/@outfitter/mcp-zmc7ht6z.js +0 -28
  51. package/dist/shared/@outfitter/mcp-zv3ej45k.js +0 -143
  52. package/dist/shared/@outfitter/mcp-zy7b487d.js +0 -5
@@ -0,0 +1,2 @@
1
+ import { ContentAnnotations } from "../shared/@outfitter/mcp-q5hr7227.js";
2
+ export { ContentAnnotations };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,24 @@
1
+ import { McpServerOptions } from "../shared/@outfitter/mcp-7btcghjj.js";
2
+ import "../shared/@outfitter/mcp-knc1gq0g.js";
3
+ import "../shared/@outfitter/mcp-9ry52yg3.js";
4
+ import "../shared/@outfitter/mcp-dgwj3jna.js";
5
+ import "../shared/@outfitter/mcp-q5hr7227.js";
6
+ import { McpLogLevel } from "../shared/@outfitter/mcp-cqpyer9m.js";
7
+ import { Sink } from "@outfitter/logging";
8
+ /** Valid MCP log levels for env var and option validation. */
9
+ declare const VALID_MCP_LOG_LEVELS: ReadonlySet<string>;
10
+ /** Map from EnvironmentDefaults logLevel to McpLogLevel. */
11
+ declare const DEFAULTS_TO_MCP: Readonly<Record<string, McpLogLevel>>;
12
+ /** Create a stderr sink with plain-text formatting for fallback logging. */
13
+ declare function createDefaultMcpSink(): Sink;
14
+ /**
15
+ * Resolve the default client log level from the precedence chain.
16
+ *
17
+ * Precedence (highest wins):
18
+ * 1. `OUTFITTER_LOG_LEVEL` environment variable
19
+ * 2. `options.defaultLogLevel` (validated against MCP levels)
20
+ * 3. Environment profile (`OUTFITTER_ENV`)
21
+ * 4. `null` (no forwarding)
22
+ */
23
+ declare function resolveDefaultLogLevel(options: McpServerOptions): McpLogLevel | null;
24
+ export { resolveDefaultLogLevel, createDefaultMcpSink, VALID_MCP_LOG_LEVELS, DEFAULTS_TO_MCP };
@@ -0,0 +1,13 @@
1
+ // @bun
2
+ import {
3
+ DEFAULTS_TO_MCP,
4
+ VALID_MCP_LOG_LEVELS,
5
+ createDefaultMcpSink,
6
+ resolveDefaultLogLevel
7
+ } from "../shared/@outfitter/mcp-n9vzcp37.js";
8
+ export {
9
+ resolveDefaultLogLevel,
10
+ createDefaultMcpSink,
11
+ VALID_MCP_LOG_LEVELS,
12
+ DEFAULTS_TO_MCP
13
+ };
@@ -0,0 +1,3 @@
1
+ import { CompletionHandler, CompletionRef, CompletionResult, PromptArgument, PromptDefinition, PromptHandler, PromptMessage, PromptMessageContent, PromptResult } from "../shared/@outfitter/mcp-dgwj3jna.js";
2
+ import "../shared/@outfitter/mcp-q5hr7227.js";
3
+ export { PromptResult, PromptMessageContent, PromptMessage, PromptHandler, PromptDefinition, PromptArgument, CompletionResult, CompletionRef, CompletionHandler };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,4 @@
1
+ import { BlobResourceContent, ResourceContent, ResourceDefinition, ResourceReadHandler, ResourceTemplateDefinition, ResourceTemplateReadHandler, TextResourceContent, TypedResourceTemplateDefinition, TypedResourceTemplateReadHandler } from "../shared/@outfitter/mcp-9ry52yg3.js";
2
+ import "../shared/@outfitter/mcp-dgwj3jna.js";
3
+ import { ContentAnnotations } from "../shared/@outfitter/mcp-q5hr7227.js";
4
+ export { TypedResourceTemplateReadHandler, TypedResourceTemplateDefinition, TextResourceContent, ResourceTemplateReadHandler, ResourceTemplateDefinition, ResourceReadHandler, ResourceDefinition, ResourceContent, ContentAnnotations, BlobResourceContent };
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,7 @@
1
+ import { InvokeToolOptions, McpError, McpHandlerContext, McpServer, McpServerOptions, ProgressReporter, Result, TaggedError, adaptHandler } from "../shared/@outfitter/mcp-7btcghjj.js";
2
+ import "../shared/@outfitter/mcp-knc1gq0g.js";
3
+ import "../shared/@outfitter/mcp-9ry52yg3.js";
4
+ import "../shared/@outfitter/mcp-dgwj3jna.js";
5
+ import "../shared/@outfitter/mcp-q5hr7227.js";
6
+ import "../shared/@outfitter/mcp-cqpyer9m.js";
7
+ export { adaptHandler, TaggedError, Result, ProgressReporter, McpServerOptions, McpServer, McpHandlerContext, McpError, InvokeToolOptions };
@@ -0,0 +1,20 @@
1
+ // @bun
2
+ // packages/mcp/src/internal/server-types.ts
3
+ import {
4
+ TaggedError as TaggedErrorImpl
5
+ } from "@outfitter/contracts";
6
+ import { TaggedError } from "@outfitter/contracts";
7
+ var TaggedError2 = TaggedErrorImpl;
8
+ var McpErrorBase = TaggedError2("McpError")();
9
+
10
+ class McpError extends McpErrorBase {
11
+ category = "internal";
12
+ }
13
+ function adaptHandler(handler) {
14
+ return handler;
15
+ }
16
+ export {
17
+ adaptHandler,
18
+ TaggedError,
19
+ McpError
20
+ };
@@ -0,0 +1,2 @@
1
+ import { SerializedTool, TOOL_ANNOTATIONS, ToolAnnotations, ToolDefinition } from "../shared/@outfitter/mcp-knc1gq0g.js";
2
+ export { ToolDefinition, ToolAnnotations, TOOL_ANNOTATIONS, SerializedTool };
@@ -1,10 +1,5 @@
1
1
  // @bun
2
- // packages/mcp/src/types.ts
3
- import {
4
- TaggedError as TaggedErrorImpl
5
- } from "@outfitter/contracts";
6
- import { TaggedError } from "@outfitter/contracts";
7
- var TaggedError2 = TaggedErrorImpl;
2
+ // packages/mcp/src/internal/tool-types.ts
8
3
  var TOOL_ANNOTATIONS = {
9
4
  readOnly: {
10
5
  readOnlyHint: true,
@@ -37,13 +32,6 @@ var TOOL_ANNOTATIONS = {
37
32
  openWorldHint: true
38
33
  }
39
34
  };
40
- var McpErrorBase = TaggedError2("McpError")();
41
-
42
- class McpError extends McpErrorBase {
43
- category = "internal";
44
- }
45
- function adaptHandler(handler) {
46
- return handler;
47
- }
48
-
49
- export { TOOL_ANNOTATIONS, McpError, adaptHandler, TaggedError };
35
+ export {
36
+ TOOL_ANNOTATIONS
37
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Match a URI against a RFC 6570 Level 1 URI template.
3
+ *
4
+ * Extracts named variables from `{param}` segments.
5
+ * Returns null if the URI doesn't match the template.
6
+ */
7
+ declare function matchUriTemplate(template: string, uri: string): Record<string, string> | null;
8
+ export { matchUriTemplate };
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ matchUriTemplate
4
+ } from "../shared/@outfitter/mcp-zt2s3r38.js";
5
+ export {
6
+ matchUriTemplate
7
+ };
@@ -0,0 +1,2 @@
1
+ import { McpNotificationSender, McpProgressNotification, createMcpProgressCallback } from "./shared/@outfitter/mcp-r27vbpc1.js";
2
+ export { createMcpProgressCallback, McpProgressNotification, McpNotificationSender };
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import {
3
+ createMcpProgressCallback
4
+ } from "./shared/@outfitter/mcp-q70dtfj6.js";
5
+ export {
6
+ createMcpProgressCallback
7
+ };
package/dist/schema.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  zodToJsonSchema
4
- } from "./shared/@outfitter/mcp-zy7b487d.js";
4
+ } from "./shared/@outfitter/mcp-hw5wz4gb.js";
5
5
  export {
6
6
  zodToJsonSchema
7
7
  };
package/dist/server.d.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-5b5726ga.js";
2
- import "./shared/@outfitter/mcp-fks4zt1z.js";
1
+ import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-3hxaatj9.js";
2
+ import "./shared/@outfitter/mcp-qmdmgxa1.js";
3
+ import "./shared/@outfitter/mcp-7btcghjj.js";
4
+ import "./shared/@outfitter/mcp-knc1gq0g.js";
5
+ import "./shared/@outfitter/mcp-9ry52yg3.js";
6
+ import "./shared/@outfitter/mcp-dgwj3jna.js";
7
+ import "./shared/@outfitter/mcp-q5hr7227.js";
3
8
  import "./shared/@outfitter/mcp-cqpyer9m.js";
4
9
  export { defineTool, defineResourceTemplate, defineResource, definePrompt, createMcpServer };
package/dist/server.js CHANGED
@@ -5,10 +5,13 @@ import {
5
5
  defineResource,
6
6
  defineResourceTemplate,
7
7
  defineTool
8
- } from "./shared/@outfitter/mcp-hh12tqfg.js";
8
+ } from "./shared/@outfitter/mcp-yf1n85e9.js";
9
+ import"./shared/@outfitter/mcp-n9vzcp37.js";
10
+ import"./shared/@outfitter/mcp-zt2s3r38.js";
11
+ import"./shared/@outfitter/mcp-q70dtfj6.js";
9
12
  import"./shared/@outfitter/mcp-fjtxsa0x.js";
10
- import"./shared/@outfitter/mcp-zy7b487d.js";
11
- import"./shared/@outfitter/mcp-9m5hs2z0.js";
13
+ import"./shared/@outfitter/mcp-s2vnhzav.js";
14
+ import"./shared/@outfitter/mcp-hw5wz4gb.js";
12
15
  export {
13
16
  defineTool,
14
17
  defineResourceTemplate,
@@ -1,4 +1,7 @@
1
- import { McpServer, McpServerOptions, PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ToolDefinition } from "./mcp-fks4zt1z.js";
1
+ import { McpServer, McpServerOptions } from "./mcp-7btcghjj.js";
2
+ import { ToolDefinition } from "./mcp-knc1gq0g.js";
3
+ import { ResourceDefinition, ResourceTemplateDefinition, TypedResourceTemplateDefinition } from "./mcp-9ry52yg3.js";
4
+ import { PromptDefinition } from "./mcp-dgwj3jna.js";
2
5
  import { OutfitterError } from "@outfitter/contracts";
3
6
  /**
4
7
  * Create an MCP server instance.
@@ -82,14 +85,42 @@ declare function defineTool<
82
85
  */
83
86
  declare function defineResource(definition: ResourceDefinition): ResourceDefinition;
84
87
  /**
85
- * Define a resource template.
88
+ * Define a resource template with optional Zod schema validation.
86
89
  *
87
- * Helper function for creating resource template definitions
88
- * with URI pattern matching.
90
+ * When `paramSchema` is provided, URI template variables are validated
91
+ * and coerced before handler invocation — parallel to how `defineTool()`
92
+ * validates input via `inputSchema`. Invalid parameters produce an
93
+ * McpError with code -32602 (Invalid params) and the handler is never called.
89
94
  *
90
- * @param definition - Resource template definition object
91
- * @returns The same resource template definition
95
+ * @param definition - Resource template definition with optional `paramSchema`
96
+ * @returns A `ResourceTemplateDefinition` compatible with `registerResourceTemplate()`
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // With Zod schema validation (recommended for typed params)
101
+ * const userTemplate = defineResourceTemplate({
102
+ * uriTemplate: "db:///users/{userId}/posts/{postId}",
103
+ * name: "User Post",
104
+ * paramSchema: z.object({
105
+ * userId: z.string().min(1),
106
+ * postId: z.coerce.number().int().positive(),
107
+ * }),
108
+ * handler: async (uri, params, ctx) => {
109
+ * // params is typed as { userId: string; postId: number }
110
+ * return Result.ok([{ uri, text: JSON.stringify(params) }]);
111
+ * },
112
+ * });
113
+ *
114
+ * // Without schema (backward compatible)
115
+ * const simpleTemplate = defineResourceTemplate({
116
+ * uriTemplate: "db:///items/{itemId}",
117
+ * name: "Item",
118
+ * handler: async (uri, variables) =>
119
+ * Result.ok([{ uri, text: variables.itemId }]),
120
+ * });
121
+ * ```
92
122
  */
123
+ declare function defineResourceTemplate<TParams>(definition: TypedResourceTemplateDefinition<TParams>): ResourceTemplateDefinition;
93
124
  declare function defineResourceTemplate(definition: ResourceTemplateDefinition): ResourceTemplateDefinition;
94
125
  /**
95
126
  * Define a prompt.
@@ -1,4 +1,4 @@
1
- import { ToolDefinition } from "./mcp-fks4zt1z.js";
1
+ import { ToolDefinition } from "./mcp-knc1gq0g.js";
2
2
  import { HandlerContext, OutfitterError } from "@outfitter/contracts";
3
3
  import { Result } from "@outfitter/contracts";
4
4
  type DocsSection = "overview" | "tools" | "examples" | "schemas";
@@ -0,0 +1,304 @@
1
+ import { SerializedTool, ToolDefinition } from "./mcp-knc1gq0g.js";
2
+ import { ResourceContent, ResourceDefinition, ResourceTemplateDefinition } from "./mcp-9ry52yg3.js";
3
+ import { CompletionRef, CompletionResult, PromptArgument, PromptDefinition, PromptResult } from "./mcp-dgwj3jna.js";
4
+ import { McpLogLevel } from "./mcp-cqpyer9m.js";
5
+ import { Handler, HandlerContext, Logger, OutfitterError, Result, TaggedErrorClass } from "@outfitter/contracts";
6
+ import { Result as Result2 } from "@outfitter/contracts";
7
+ import { TaggedError } from "@outfitter/contracts";
8
+ /**
9
+ * Configuration options for creating an MCP server.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const options: McpServerOptions = {
14
+ * name: "my-mcp-server",
15
+ * version: "1.0.0",
16
+ * logger: createLogger({ name: "mcp" }),
17
+ * };
18
+ *
19
+ * const server = createMcpServer(options);
20
+ * ```
21
+ */
22
+ interface McpServerOptions {
23
+ /**
24
+ * Default MCP log level for client-facing log forwarding.
25
+ *
26
+ * Precedence (highest wins):
27
+ * 1. `OUTFITTER_LOG_LEVEL` environment variable
28
+ * 2. This option
29
+ * 3. Environment profile (`OUTFITTER_ENV`)
30
+ * 4. `null` (no forwarding until client opts in)
31
+ *
32
+ * Set to `null` to explicitly disable forwarding regardless of environment.
33
+ * The MCP client can always override via `logging/setLevel`.
34
+ */
35
+ defaultLogLevel?: McpLogLevel | null;
36
+ /**
37
+ * Optional logger instance for server logging.
38
+ * If not provided, the server uses the Outfitter logger factory defaults.
39
+ */
40
+ logger?: Logger;
41
+ /**
42
+ * Server name, used in MCP protocol handshake.
43
+ * Should be a short, descriptive identifier.
44
+ */
45
+ name: string;
46
+ /**
47
+ * Server version (semver format recommended).
48
+ * Sent to clients during initialization.
49
+ */
50
+ version: string;
51
+ }
52
+ declare const McpErrorBase: TaggedErrorClass<"McpError", {
53
+ message: string;
54
+ code: number;
55
+ context?: Record<string, unknown>;
56
+ }>;
57
+ /**
58
+ * MCP-specific error with JSON-RPC error code.
59
+ *
60
+ * Used when tool invocations fail or when there are protocol-level errors.
61
+ * Follows the JSON-RPC 2.0 error object format.
62
+ *
63
+ * Standard error codes:
64
+ * - `-32700`: Parse error
65
+ * - `-32600`: Invalid request
66
+ * - `-32601`: Method not found
67
+ * - `-32602`: Invalid params
68
+ * - `-32603`: Internal error
69
+ * - `-32000` to `-32099`: Server errors (reserved)
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const error = new McpError({
74
+ * message: "Tool not found: unknown-tool",
75
+ * code: -32601,
76
+ * context: { tool: "unknown-tool" },
77
+ * });
78
+ * ```
79
+ */
80
+ declare class McpError extends McpErrorBase {
81
+ /** Error category for Outfitter error taxonomy compatibility */
82
+ readonly category: "internal";
83
+ }
84
+ /**
85
+ * Options for invoking a tool.
86
+ */
87
+ interface InvokeToolOptions {
88
+ /** Progress token from client for tracking progress */
89
+ progressToken?: string | number;
90
+ /** Custom request ID (auto-generated if not provided) */
91
+ requestId?: string;
92
+ /** Abort signal for cancellation */
93
+ signal?: AbortSignal;
94
+ }
95
+ /**
96
+ * MCP Server instance.
97
+ *
98
+ * Provides methods for registering tools and resources, and for
99
+ * starting/stopping the server.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const server = createMcpServer({
104
+ * name: "my-server",
105
+ * version: "1.0.0",
106
+ * });
107
+ *
108
+ * server.registerTool(myTool);
109
+ * server.registerResource(myResource);
110
+ *
111
+ * await server.start();
112
+ * ```
113
+ */
114
+ interface McpServer {
115
+ /**
116
+ * Bind the SDK server instance for notifications.
117
+ * Called internally by the transport layer.
118
+ * @param sdkServer - The MCP SDK Server instance
119
+ */
120
+ bindSdkServer?(sdkServer: any): void;
121
+ /**
122
+ * Complete an argument value.
123
+ * @param ref - Reference to the prompt or resource template
124
+ * @param argumentName - Name of the argument to complete
125
+ * @param value - Current value to complete
126
+ * @returns Result with completion values or McpError
127
+ */
128
+ complete(ref: CompletionRef, argumentName: string, value: string): Promise<Result<CompletionResult, InstanceType<typeof McpError>>>;
129
+ /**
130
+ * Get a specific prompt's messages.
131
+ * @param name - Prompt name
132
+ * @param args - Prompt arguments
133
+ * @returns Result with prompt result or McpError
134
+ */
135
+ getPrompt(name: string, args: Record<string, string | undefined>): Promise<Result<PromptResult, InstanceType<typeof McpError>>>;
136
+ /**
137
+ * Get all registered prompts.
138
+ * @returns Array of prompt definitions (without handlers)
139
+ */
140
+ getPrompts(): Array<{
141
+ name: string;
142
+ description?: string;
143
+ arguments: PromptArgument[];
144
+ }>;
145
+ /**
146
+ * Get all registered resources.
147
+ * @returns Array of resource definitions
148
+ */
149
+ getResources(): ResourceDefinition[];
150
+ /**
151
+ * Get all registered resource templates.
152
+ * @returns Array of resource template definitions
153
+ */
154
+ getResourceTemplates(): ResourceTemplateDefinition[];
155
+ /**
156
+ * Get all registered tools.
157
+ * @returns Array of serialized tool information
158
+ */
159
+ getTools(): SerializedTool[];
160
+ /**
161
+ * Invoke a tool by name.
162
+ * @param name - Tool name
163
+ * @param input - Tool input (will be validated)
164
+ * @param options - Optional invocation options
165
+ * @returns Result with tool output or McpError
166
+ */
167
+ invokeTool<T = unknown>(name: string, input: unknown, options?: InvokeToolOptions): Promise<Result<T, InstanceType<typeof McpError>>>;
168
+ /** Server name */
169
+ readonly name: string;
170
+ /**
171
+ * Notify connected clients that the prompt list has changed.
172
+ */
173
+ notifyPromptsChanged(): void;
174
+ /**
175
+ * Notify connected clients that the resource list has changed.
176
+ */
177
+ notifyResourcesChanged(): void;
178
+ /**
179
+ * Notify connected clients that a specific resource has been updated.
180
+ * Only emits for subscribed URIs.
181
+ * @param uri - URI of the updated resource
182
+ */
183
+ notifyResourceUpdated(uri: string): void;
184
+ /**
185
+ * Notify connected clients that the tool list has changed.
186
+ */
187
+ notifyToolsChanged(): void;
188
+ /**
189
+ * Read a resource by URI.
190
+ * @param uri - Resource URI
191
+ * @returns Result with resource content or McpError
192
+ */
193
+ readResource(uri: string): Promise<Result<ResourceContent[], InstanceType<typeof McpError>>>;
194
+ /**
195
+ * Register a prompt with the server.
196
+ * @param prompt - Prompt definition to register
197
+ */
198
+ registerPrompt(prompt: PromptDefinition): void;
199
+ /**
200
+ * Register a resource with the server.
201
+ * @param resource - Resource definition to register
202
+ */
203
+ registerResource(resource: ResourceDefinition): void;
204
+ /**
205
+ * Register a resource template with the server.
206
+ * @param template - Resource template definition to register
207
+ */
208
+ registerResourceTemplate(template: ResourceTemplateDefinition): void;
209
+ /**
210
+ * Register a tool with the server.
211
+ * @param tool - Tool definition to register
212
+ */
213
+ registerTool<
214
+ TInput,
215
+ TOutput,
216
+ TError extends OutfitterError
217
+ >(tool: ToolDefinition<TInput, TOutput, TError>): void;
218
+ /**
219
+ * Send a log message to connected clients.
220
+ * Filters by the client-requested log level threshold.
221
+ * No-op if no SDK server is bound or if the message is below the threshold.
222
+ *
223
+ * @param level - MCP log level for the message
224
+ * @param data - Log data (string, object, or any serializable value)
225
+ * @param loggerName - Optional logger name for client-side filtering
226
+ */
227
+ sendLogMessage(level: McpLogLevel, data: unknown, loggerName?: string): void;
228
+ /**
229
+ * Set the client-requested log level.
230
+ * Only log messages at or above this level will be forwarded.
231
+ * @param level - MCP log level string
232
+ */
233
+ setLogLevel?(level: string): void;
234
+ /**
235
+ * Start the MCP server.
236
+ * Begins listening for client connections.
237
+ */
238
+ start(): Promise<void>;
239
+ /**
240
+ * Stop the MCP server.
241
+ * Closes all connections and cleans up resources.
242
+ */
243
+ stop(): Promise<void>;
244
+ /**
245
+ * Subscribe to updates for a resource URI.
246
+ * @param uri - Resource URI to subscribe to
247
+ */
248
+ subscribe(uri: string): void;
249
+ /**
250
+ * Unsubscribe from updates for a resource URI.
251
+ * @param uri - Resource URI to unsubscribe from
252
+ */
253
+ unsubscribe(uri: string): void;
254
+ /** Server version */
255
+ readonly version: string;
256
+ }
257
+ type HandlerProgress = HandlerContext extends {
258
+ progress?: infer P;
259
+ } ? P : never;
260
+ type LegacyProgressReporter = {
261
+ report(progress: number, total?: number, message?: string): void;
262
+ };
263
+ /**
264
+ * Backward-compatible progress reporter type.
265
+ *
266
+ * - When `HandlerContext.progress` exists (streaming branches), this becomes
267
+ * `ProgressCallback & { report(...) }`.
268
+ * - When it does not exist (older branches), this falls back to
269
+ * `{ report(...) }`.
270
+ */
271
+ type ProgressReporter = [HandlerProgress] extends [never] ? LegacyProgressReporter : NonNullable<HandlerProgress> & LegacyProgressReporter;
272
+ /**
273
+ * Extended handler context for MCP tools.
274
+ * Includes MCP-specific information in addition to standard HandlerContext.
275
+ */
276
+ interface McpHandlerContext extends Omit<HandlerContext, "progress"> {
277
+ /** Progress reporter, present when client provides a progressToken */
278
+ progress?: ProgressReporter;
279
+ /** The name of the tool being invoked */
280
+ toolName?: string;
281
+ }
282
+ /**
283
+ * Adapt a handler with a domain error type for use with MCP tools.
284
+ *
285
+ * MCP tool definitions constrain `TError extends OutfitterError`. When your
286
+ * handler returns domain-specific errors that extend `Error` but not
287
+ * `OutfitterError`, use this function instead of an unsafe cast:
288
+ *
289
+ * ```typescript
290
+ * import { adaptHandler } from "@outfitter/mcp";
291
+ *
292
+ * const tool = defineTool({
293
+ * name: "my-tool",
294
+ * inputSchema: z.object({ id: z.string() }),
295
+ * handler: adaptHandler(myDomainHandler),
296
+ * });
297
+ * ```
298
+ */
299
+ declare function adaptHandler<
300
+ TInput,
301
+ TOutput,
302
+ TError extends Error
303
+ >(handler: (input: TInput, ctx: HandlerContext) => Promise<Result<TOutput, TError>>): Handler<TInput, TOutput, OutfitterError>;
304
+ export { McpServerOptions, McpError, InvokeToolOptions, McpServer, ProgressReporter, McpHandlerContext, adaptHandler, Result2 as Result, TaggedError };