@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
package/dist/index.d.ts CHANGED
@@ -1,953 +1,14 @@
1
- import { ActionRegistry, ActionSurface, AnyActionSpec } from "@outfitter/contracts";
2
- import { Handler, HandlerContext, Logger, OutfitterError, Result, TaggedErrorClass } from "@outfitter/contracts";
3
- import { z } from "zod";
4
- /**
5
- * @outfitter/mcp - Logging Bridge
6
- *
7
- * Maps Outfitter log levels to MCP log levels for
8
- * server-to-client log message notifications.
9
- *
10
- * @packageDocumentation
11
- */
12
- /**
13
- * MCP log levels as defined in the MCP specification.
14
- * Ordered from least to most severe.
15
- */
16
- type McpLogLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
17
- /**
18
- * Outfitter log levels.
19
- */
20
- type OutfitterLogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
21
- /**
22
- * Map an Outfitter log level to the corresponding MCP log level.
23
- */
24
- declare function mapLogLevelToMcp(level: OutfitterLogLevel): McpLogLevel;
25
- /**
26
- * Check whether a message at the given level should be emitted
27
- * based on the client-requested threshold.
28
- */
29
- declare function shouldEmitLog(messageLevel: McpLogLevel, threshold: McpLogLevel): boolean;
30
- /**
31
- * Configuration options for creating an MCP server.
32
- *
33
- * @example
34
- * ```typescript
35
- * const options: McpServerOptions = {
36
- * name: "my-mcp-server",
37
- * version: "1.0.0",
38
- * logger: createLogger({ name: "mcp" }),
39
- * };
40
- *
41
- * const server = createMcpServer(options);
42
- * ```
43
- */
44
- interface McpServerOptions {
45
- /**
46
- * Default MCP log level for client-facing log forwarding.
47
- *
48
- * Precedence (highest wins):
49
- * 1. `OUTFITTER_LOG_LEVEL` environment variable
50
- * 2. This option
51
- * 3. Environment profile (`OUTFITTER_ENV`)
52
- * 4. `null` (no forwarding until client opts in)
53
- *
54
- * Set to `null` to explicitly disable forwarding regardless of environment.
55
- * The MCP client can always override via `logging/setLevel`.
56
- */
57
- defaultLogLevel?: McpLogLevel | null;
58
- /**
59
- * Optional logger instance for server logging.
60
- * If not provided, the server uses the Outfitter logger factory defaults.
61
- */
62
- logger?: Logger;
63
- /**
64
- * Server name, used in MCP protocol handshake.
65
- * Should be a short, descriptive identifier.
66
- */
67
- name: string;
68
- /**
69
- * Server version (semver format recommended).
70
- * Sent to clients during initialization.
71
- */
72
- version: string;
73
- }
74
- /**
75
- * Behavioral hints for MCP tools.
76
- *
77
- * Annotations help clients understand tool behavior without invoking them.
78
- * All fields are optional — only include hints that apply.
79
- *
80
- * @see https://spec.modelcontextprotocol.io/specification/2025-03-26/server/tools/#annotations
81
- */
82
- interface ToolAnnotations {
83
- /** When true, the tool may perform destructive operations (e.g., deleting data). */
84
- destructiveHint?: boolean;
85
- /** When true, calling the tool multiple times with the same input has the same effect. */
86
- idempotentHint?: boolean;
87
- /** When true, the tool may interact with external systems beyond the server. */
88
- openWorldHint?: boolean;
89
- /** When true, the tool does not modify any state. */
90
- readOnlyHint?: boolean;
91
- }
92
- /**
93
- * Common annotation presets for MCP tools.
94
- *
95
- * Use these as a starting point and spread-override individual hints:
96
- *
97
- * ```typescript
98
- * annotations: { ...TOOL_ANNOTATIONS.readOnly, openWorldHint: true }
99
- * ```
100
- *
101
- * For multi-action tools (e.g., a single tool with read and write actions),
102
- * use the most conservative union of hints — if any action is destructive,
103
- * mark the whole tool as destructive. Per-action annotations are an MCP spec
104
- * limitation; presets + spread cover most edge cases.
105
- */
106
- declare const TOOL_ANNOTATIONS: {
107
- /** Read-only, safe to call repeatedly. */
108
- readonly readOnly: {
109
- readonly readOnlyHint: true;
110
- readonly destructiveHint: false;
111
- readonly idempotentHint: true;
112
- readonly openWorldHint: false;
113
- };
114
- /** Creates or updates state, not destructive. */
115
- readonly write: {
116
- readonly readOnlyHint: false;
117
- readonly destructiveHint: false;
118
- readonly idempotentHint: false;
119
- readonly openWorldHint: false;
120
- };
121
- /** Idempotent write (PUT-like). */
122
- readonly writeIdempotent: {
123
- readonly readOnlyHint: false;
124
- readonly destructiveHint: false;
125
- readonly idempotentHint: true;
126
- readonly openWorldHint: false;
127
- };
128
- /** Deletes or permanently modifies data. */
129
- readonly destructive: {
130
- readonly readOnlyHint: false;
131
- readonly destructiveHint: true;
132
- readonly idempotentHint: true;
133
- readonly openWorldHint: false;
134
- };
135
- /** Interacts with external systems (APIs, network). */
136
- readonly openWorld: {
137
- readonly readOnlyHint: false;
138
- readonly destructiveHint: false;
139
- readonly idempotentHint: false;
140
- readonly openWorldHint: true;
141
- };
142
- };
143
- /**
144
- * Definition of an MCP tool that can be invoked by clients.
145
- *
146
- * Tools are the primary way clients interact with MCP servers.
147
- * Each tool has a name, description, input schema (for validation),
148
- * and a handler function that processes requests.
149
- *
150
- * @typeParam TInput - The validated input type (inferred from Zod schema)
151
- * @typeParam TOutput - The success output type
152
- * @typeParam TError - The error type (must extend OutfitterError)
153
- *
154
- * @example
155
- * ```typescript
156
- * const getUserTool: ToolDefinition<
157
- * { userId: string },
158
- * { name: string; email: string },
159
- * NotFoundError
160
- * > = {
161
- * name: "get-user",
162
- * description: "Retrieve a user by ID",
163
- * inputSchema: z.object({ userId: z.string().uuid() }),
164
- * handler: async (input, ctx) => {
165
- * ctx.logger.debug("Fetching user", { userId: input.userId });
166
- * const user = await db.users.find(input.userId);
167
- * if (!user) {
168
- * return Result.err(new NotFoundError({
169
- * message: `User ${input.userId} not found`,
170
- * resourceType: "user",
171
- * resourceId: input.userId,
172
- * }));
173
- * }
174
- * return Result.ok({ name: user.name, email: user.email });
175
- * },
176
- * };
177
- * ```
178
- */
179
- interface ToolDefinition<
180
- TInput,
181
- TOutput,
182
- TError extends OutfitterError = OutfitterError
183
- > {
184
- /**
185
- * Optional behavioral annotations for the tool.
186
- * Helps clients understand tool behavior without invoking it.
187
- */
188
- annotations?: ToolAnnotations;
189
- /**
190
- * Whether the tool should be deferred for tool search.
191
- * Defaults to true for domain tools; core tools set this to false.
192
- */
193
- deferLoading?: boolean;
194
- /**
195
- * Human-readable description of what the tool does.
196
- * Shown to clients and used by LLMs to understand tool capabilities.
197
- */
198
- description: string;
199
- /**
200
- * Handler function that processes the tool invocation.
201
- * Receives validated input and HandlerContext, returns Result.
202
- */
203
- handler: Handler<TInput, TOutput, TError>;
204
- /**
205
- * Zod schema for validating and parsing input.
206
- * The schema defines the expected input structure.
207
- */
208
- inputSchema: z.ZodType<TInput>;
209
- /**
210
- * Unique tool name (kebab-case recommended).
211
- * Used by clients to invoke the tool.
212
- */
213
- name: string;
214
- }
215
- /**
216
- * Serialized tool information for MCP protocol.
217
- * This is the format sent to clients during tool listing.
218
- */
219
- interface SerializedTool {
220
- /** Behavioral annotations for the tool */
221
- annotations?: ToolAnnotations;
222
- /** MCP tool-search hint: whether tool is deferred */
223
- defer_loading?: boolean;
224
- /** Tool description */
225
- description: string;
226
- /** JSON Schema representation of the input schema */
227
- inputSchema: Record<string, unknown>;
228
- /** Tool name */
229
- name: string;
230
- }
231
- /**
232
- * Annotations for content items (resource content, prompt messages).
233
- *
234
- * Provides hints about content audience and priority.
235
- *
236
- * @see https://spec.modelcontextprotocol.io/specification/2025-03-26/server/utilities/annotations/
237
- */
238
- interface ContentAnnotations {
239
- /**
240
- * Who the content is intended for.
241
- * Can include "user", "assistant", or both.
242
- */
243
- audience?: Array<"user" | "assistant">;
244
- /**
245
- * Priority level from 0.0 (least) to 1.0 (most important).
246
- */
247
- priority?: number;
248
- }
249
- /**
250
- * Text content returned from a resource read.
251
- */
252
- interface TextResourceContent {
253
- /** Optional content annotations */
254
- annotations?: ContentAnnotations;
255
- /** Optional MIME type */
256
- mimeType?: string;
257
- /** Text content */
258
- text: string;
259
- /** Resource URI */
260
- uri: string;
261
- }
262
- /**
263
- * Binary (base64-encoded) content returned from a resource read.
264
- */
265
- interface BlobResourceContent {
266
- /** Optional content annotations */
267
- annotations?: ContentAnnotations;
268
- /** Base64-encoded binary content */
269
- blob: string;
270
- /** Optional MIME type */
271
- mimeType?: string;
272
- /** Resource URI */
273
- uri: string;
274
- }
275
- /**
276
- * Content returned from reading a resource.
277
- */
278
- type ResourceContent = TextResourceContent | BlobResourceContent;
279
- /**
280
- * Handler for reading a resource's content.
281
- *
282
- * @param uri - The resource URI being read
283
- * @param ctx - Handler context with logger and requestId
284
- * @returns Array of resource content items
285
- */
286
- type ResourceReadHandler = (uri: string, ctx: HandlerContext) => Promise<Result<ResourceContent[], OutfitterError>>;
287
- /**
288
- * Definition of an MCP resource that can be read by clients.
289
- *
290
- * Resources represent data that clients can access, such as files,
291
- * database records, or API responses.
292
- *
293
- * @example
294
- * ```typescript
295
- * const configResource: ResourceDefinition = {
296
- * uri: "file:///etc/app/config.json",
297
- * name: "Application Config",
298
- * description: "Main application configuration file",
299
- * mimeType: "application/json",
300
- * handler: async (uri, ctx) => {
301
- * const content = await readFile(uri);
302
- * return Result.ok([{ uri, text: content }]);
303
- * },
304
- * };
305
- * ```
306
- */
307
- interface ResourceDefinition {
308
- /**
309
- * Optional description of the resource.
310
- * Provides additional context about the resource contents.
311
- */
312
- description?: string;
313
- /**
314
- * Optional handler for reading the resource content.
315
- * If not provided, the resource is metadata-only.
316
- */
317
- handler?: ResourceReadHandler;
318
- /**
319
- * Optional MIME type of the resource content.
320
- * Helps clients understand how to process the resource.
321
- */
322
- mimeType?: string;
323
- /**
324
- * Human-readable resource name.
325
- * Displayed to users in resource listings.
326
- */
327
- name: string;
328
- /**
329
- * Unique resource URI.
330
- * Must be a valid URI (file://, https://, custom://, etc.).
331
- */
332
- uri: string;
333
- }
334
- /**
335
- * Handler for reading a resource template's content.
336
- *
337
- * @param uri - The matched URI
338
- * @param variables - Extracted template variables
339
- * @param ctx - Handler context
340
- */
341
- type ResourceTemplateReadHandler = (uri: string, variables: Record<string, string>, ctx: HandlerContext) => Promise<Result<ResourceContent[], OutfitterError>>;
342
- /**
343
- * Definition of an MCP resource template with URI pattern matching.
344
- *
345
- * Templates use RFC 6570 Level 1 URI templates (e.g., `{param}`)
346
- * to match and extract variables from URIs.
347
- *
348
- * @example
349
- * ```typescript
350
- * const userTemplate: ResourceTemplateDefinition = {
351
- * uriTemplate: "db:///users/{userId}/profile",
352
- * name: "User Profile",
353
- * handler: async (uri, variables) => {
354
- * const profile = await getProfile(variables.userId);
355
- * return Result.ok([{ uri, text: JSON.stringify(profile) }]);
356
- * },
357
- * };
358
- * ```
359
- */
360
- interface ResourceTemplateDefinition {
361
- /** Optional completion handlers keyed by parameter name. */
362
- complete?: Record<string, CompletionHandler>;
363
- /** Optional description. */
364
- description?: string;
365
- /** Handler for reading matched resources. */
366
- handler: ResourceTemplateReadHandler;
367
- /** Optional MIME type. */
368
- mimeType?: string;
369
- /** Human-readable name for the template. */
370
- name: string;
371
- /** URI template with `{param}` placeholders (RFC 6570 Level 1). */
372
- uriTemplate: string;
373
- }
374
- /**
375
- * Result of a completion request.
376
- */
377
- interface CompletionResult {
378
- /** Whether there are more values */
379
- hasMore?: boolean;
380
- /** Total number of available values (for pagination) */
381
- total?: number;
382
- /** Completion values */
383
- values: string[];
384
- }
385
- /**
386
- * Handler for generating completions.
387
- */
388
- type CompletionHandler = (value: string) => Promise<CompletionResult>;
389
- /**
390
- * Reference to a prompt or resource for completion.
391
- */
392
- type CompletionRef = {
393
- type: "ref/prompt";
394
- name: string;
395
- } | {
396
- type: "ref/resource";
397
- uri: string;
398
- };
399
- /**
400
- * Argument definition for a prompt.
401
- */
402
- interface PromptArgument {
403
- /** Optional completion handler for this argument */
404
- complete?: CompletionHandler;
405
- /** Human-readable description */
406
- description?: string;
407
- /** Argument name */
408
- name: string;
409
- /** Whether this argument is required */
410
- required?: boolean;
411
- }
412
- /**
413
- * Content block within a prompt message.
414
- */
415
- interface PromptMessageContent {
416
- /** Optional content annotations */
417
- annotations?: ContentAnnotations;
418
- /** Text content */
419
- text: string;
420
- /** Content type */
421
- type: "text";
422
- }
423
- /**
424
- * A message in a prompt response.
425
- */
426
- interface PromptMessage {
427
- /** Message content */
428
- content: PromptMessageContent;
429
- /** Message role */
430
- role: "user" | "assistant";
431
- }
432
- /**
433
- * Result returned from getting a prompt.
434
- */
435
- interface PromptResult {
436
- /** Optional description override */
437
- description?: string;
438
- /** Prompt messages */
439
- messages: PromptMessage[];
440
- }
441
- /**
442
- * Handler for generating prompt messages.
443
- */
444
- type PromptHandler = (args: Record<string, string | undefined>) => Promise<Result<PromptResult, OutfitterError>>;
445
- /**
446
- * Definition of an MCP prompt.
447
- *
448
- * Prompts are reusable templates that generate messages for LLMs.
449
- *
450
- * @example
451
- * ```typescript
452
- * const reviewPrompt: PromptDefinition = {
453
- * name: "code-review",
454
- * description: "Review code changes",
455
- * arguments: [
456
- * { name: "language", description: "Programming language", required: true },
457
- * ],
458
- * handler: async (args) => Result.ok({
459
- * messages: [{ role: "user", content: { type: "text", text: `Review this ${args.language} code` } }],
460
- * }),
461
- * };
462
- * ```
463
- */
464
- interface PromptDefinition {
465
- /** Prompt arguments */
466
- arguments: PromptArgument[];
467
- /** Human-readable description */
468
- description?: string;
469
- /** Handler to generate messages */
470
- handler: PromptHandler;
471
- /** Unique prompt name */
472
- name: string;
473
- }
474
- declare const McpErrorBase: TaggedErrorClass<"McpError", {
475
- message: string;
476
- code: number;
477
- context?: Record<string, unknown>;
478
- }>;
479
- /**
480
- * MCP-specific error with JSON-RPC error code.
481
- *
482
- * Used when tool invocations fail or when there are protocol-level errors.
483
- * Follows the JSON-RPC 2.0 error object format.
484
- *
485
- * Standard error codes:
486
- * - `-32700`: Parse error
487
- * - `-32600`: Invalid request
488
- * - `-32601`: Method not found
489
- * - `-32602`: Invalid params
490
- * - `-32603`: Internal error
491
- * - `-32000` to `-32099`: Server errors (reserved)
492
- *
493
- * @example
494
- * ```typescript
495
- * const error = new McpError({
496
- * message: "Tool not found: unknown-tool",
497
- * code: -32601,
498
- * context: { tool: "unknown-tool" },
499
- * });
500
- * ```
501
- */
502
- declare class McpError extends McpErrorBase {
503
- /** Error category for Outfitter error taxonomy compatibility */
504
- readonly category: "internal";
505
- }
506
- /**
507
- * Options for invoking a tool.
508
- */
509
- interface InvokeToolOptions {
510
- /** Progress token from client for tracking progress */
511
- progressToken?: string | number;
512
- /** Custom request ID (auto-generated if not provided) */
513
- requestId?: string;
514
- /** Abort signal for cancellation */
515
- signal?: AbortSignal;
516
- }
517
- /**
518
- * MCP Server instance.
519
- *
520
- * Provides methods for registering tools and resources, and for
521
- * starting/stopping the server.
522
- *
523
- * @example
524
- * ```typescript
525
- * const server = createMcpServer({
526
- * name: "my-server",
527
- * version: "1.0.0",
528
- * });
529
- *
530
- * server.registerTool(myTool);
531
- * server.registerResource(myResource);
532
- *
533
- * await server.start();
534
- * ```
535
- */
536
- interface McpServer {
537
- /**
538
- * Bind the SDK server instance for notifications.
539
- * Called internally by the transport layer.
540
- * @param sdkServer - The MCP SDK Server instance
541
- */
542
- bindSdkServer?(sdkServer: any): void;
543
- /**
544
- * Complete an argument value.
545
- * @param ref - Reference to the prompt or resource template
546
- * @param argumentName - Name of the argument to complete
547
- * @param value - Current value to complete
548
- * @returns Result with completion values or McpError
549
- */
550
- complete(ref: CompletionRef, argumentName: string, value: string): Promise<Result<CompletionResult, InstanceType<typeof McpError>>>;
551
- /**
552
- * Get a specific prompt's messages.
553
- * @param name - Prompt name
554
- * @param args - Prompt arguments
555
- * @returns Result with prompt result or McpError
556
- */
557
- getPrompt(name: string, args: Record<string, string | undefined>): Promise<Result<PromptResult, InstanceType<typeof McpError>>>;
558
- /**
559
- * Get all registered prompts.
560
- * @returns Array of prompt definitions (without handlers)
561
- */
562
- getPrompts(): Array<{
563
- name: string;
564
- description?: string;
565
- arguments: PromptArgument[];
566
- }>;
567
- /**
568
- * Get all registered resources.
569
- * @returns Array of resource definitions
570
- */
571
- getResources(): ResourceDefinition[];
572
- /**
573
- * Get all registered resource templates.
574
- * @returns Array of resource template definitions
575
- */
576
- getResourceTemplates(): ResourceTemplateDefinition[];
577
- /**
578
- * Get all registered tools.
579
- * @returns Array of serialized tool information
580
- */
581
- getTools(): SerializedTool[];
582
- /**
583
- * Invoke a tool by name.
584
- * @param name - Tool name
585
- * @param input - Tool input (will be validated)
586
- * @param options - Optional invocation options
587
- * @returns Result with tool output or McpError
588
- */
589
- invokeTool<T = unknown>(name: string, input: unknown, options?: InvokeToolOptions): Promise<Result<T, InstanceType<typeof McpError>>>;
590
- /** Server name */
591
- readonly name: string;
592
- /**
593
- * Notify connected clients that the prompt list has changed.
594
- */
595
- notifyPromptsChanged(): void;
596
- /**
597
- * Notify connected clients that the resource list has changed.
598
- */
599
- notifyResourcesChanged(): void;
600
- /**
601
- * Notify connected clients that a specific resource has been updated.
602
- * Only emits for subscribed URIs.
603
- * @param uri - URI of the updated resource
604
- */
605
- notifyResourceUpdated(uri: string): void;
606
- /**
607
- * Notify connected clients that the tool list has changed.
608
- */
609
- notifyToolsChanged(): void;
610
- /**
611
- * Read a resource by URI.
612
- * @param uri - Resource URI
613
- * @returns Result with resource content or McpError
614
- */
615
- readResource(uri: string): Promise<Result<ResourceContent[], InstanceType<typeof McpError>>>;
616
- /**
617
- * Register a prompt with the server.
618
- * @param prompt - Prompt definition to register
619
- */
620
- registerPrompt(prompt: PromptDefinition): void;
621
- /**
622
- * Register a resource with the server.
623
- * @param resource - Resource definition to register
624
- */
625
- registerResource(resource: ResourceDefinition): void;
626
- /**
627
- * Register a resource template with the server.
628
- * @param template - Resource template definition to register
629
- */
630
- registerResourceTemplate(template: ResourceTemplateDefinition): void;
631
- /**
632
- * Register a tool with the server.
633
- * @param tool - Tool definition to register
634
- */
635
- registerTool<
636
- TInput,
637
- TOutput,
638
- TError extends OutfitterError
639
- >(tool: ToolDefinition<TInput, TOutput, TError>): void;
640
- /**
641
- * Send a log message to connected clients.
642
- * Filters by the client-requested log level threshold.
643
- * No-op if no SDK server is bound or if the message is below the threshold.
644
- *
645
- * @param level - MCP log level for the message
646
- * @param data - Log data (string, object, or any serializable value)
647
- * @param loggerName - Optional logger name for client-side filtering
648
- */
649
- sendLogMessage(level: McpLogLevel, data: unknown, loggerName?: string): void;
650
- /**
651
- * Set the client-requested log level.
652
- * Only log messages at or above this level will be forwarded.
653
- * @param level - MCP log level string
654
- */
655
- setLogLevel?(level: string): void;
656
- /**
657
- * Start the MCP server.
658
- * Begins listening for client connections.
659
- */
660
- start(): Promise<void>;
661
- /**
662
- * Stop the MCP server.
663
- * Closes all connections and cleans up resources.
664
- */
665
- stop(): Promise<void>;
666
- /**
667
- * Subscribe to updates for a resource URI.
668
- * @param uri - Resource URI to subscribe to
669
- */
670
- subscribe(uri: string): void;
671
- /**
672
- * Unsubscribe from updates for a resource URI.
673
- * @param uri - Resource URI to unsubscribe from
674
- */
675
- unsubscribe(uri: string): void;
676
- /** Server version */
677
- readonly version: string;
678
- }
679
- /**
680
- * Reporter for sending progress updates to clients.
681
- */
682
- interface ProgressReporter {
683
- /**
684
- * Report progress for the current operation.
685
- * @param progress - Current progress value
686
- * @param total - Optional total value (for percentage calculation)
687
- * @param message - Optional human-readable status message
688
- */
689
- report(progress: number, total?: number, message?: string): void;
690
- }
691
- /**
692
- * Extended handler context for MCP tools.
693
- * Includes MCP-specific information in addition to standard HandlerContext.
694
- */
695
- interface McpHandlerContext extends HandlerContext {
696
- /** Progress reporter, present when client provides a progressToken */
697
- progress?: ProgressReporter;
698
- /** The name of the tool being invoked */
699
- toolName?: string;
700
- }
701
- /**
702
- * Adapt a handler with a domain error type for use with MCP tools.
703
- *
704
- * MCP tool definitions constrain `TError extends OutfitterError`. When your
705
- * handler returns domain-specific errors that extend `Error` but not
706
- * `OutfitterError`, use this function instead of an unsafe cast:
707
- *
708
- * ```typescript
709
- * import { adaptHandler } from "@outfitter/mcp";
710
- *
711
- * const tool = defineTool({
712
- * name: "my-tool",
713
- * inputSchema: z.object({ id: z.string() }),
714
- * handler: adaptHandler(myDomainHandler),
715
- * });
716
- * ```
717
- */
718
- declare function adaptHandler<
719
- TInput,
720
- TOutput,
721
- TError extends Error
722
- >(handler: (input: TInput, ctx: HandlerContext) => Promise<Result<TOutput, TError>>): Handler<TInput, TOutput, OutfitterError>;
723
- interface BuildMcpToolsOptions {
724
- readonly includeSurfaces?: readonly ActionSurface[];
725
- }
726
- type ActionSource = ActionRegistry | readonly AnyActionSpec[];
727
- declare function buildMcpTools(source: ActionSource, options?: BuildMcpToolsOptions): ToolDefinition<unknown, unknown>[];
728
- import { HandlerContext as HandlerContext2, OutfitterError as OutfitterError2 } from "@outfitter/contracts";
729
- import { Result as Result3 } from "@outfitter/contracts";
730
- type DocsSection = "overview" | "tools" | "examples" | "schemas";
731
- interface DocsToolInput {
732
- section?: DocsSection | undefined;
733
- }
734
- interface DocsToolEntry {
735
- examples?: Array<{
736
- input: Record<string, unknown>;
737
- description?: string;
738
- }>;
739
- name: string;
740
- summary?: string;
741
- }
742
- interface DocsToolResponse {
743
- examples?: Array<{
744
- name?: string;
745
- description?: string;
746
- input?: Record<string, unknown>;
747
- output?: unknown;
748
- }>;
749
- overview?: string;
750
- schemas?: Record<string, unknown>;
751
- tools?: DocsToolEntry[];
752
- }
753
- interface DocsToolOptions {
754
- /** Optional override for the docs tool description. */
755
- description?: string;
756
- /** Static docs payload (used when getDocs is not provided). */
757
- docs?: DocsToolResponse;
758
- /** Dynamic docs provider. */
759
- getDocs?: (section?: DocsSection) => DocsToolResponse | Promise<DocsToolResponse>;
760
- }
761
- declare function defineDocsTool(options?: DocsToolOptions): ToolDefinition<DocsToolInput, DocsToolResponse>;
762
- type ConfigAction = "get" | "set" | "list";
763
- interface ConfigToolInput {
764
- action: ConfigAction;
765
- key?: string | undefined;
766
- value?: unknown | undefined;
767
- }
768
- interface ConfigToolResponse {
769
- action: ConfigAction;
770
- config?: Record<string, unknown>;
771
- found?: boolean;
772
- key?: string;
773
- value?: unknown;
774
- }
775
- interface ConfigStore {
776
- get(key: string): {
777
- value: unknown;
778
- found: boolean;
779
- } | Promise<{
780
- value: unknown;
781
- found: boolean;
782
- }>;
783
- list(): Record<string, unknown> | Promise<Record<string, unknown>>;
784
- set(key: string, value: unknown): void | Promise<void>;
785
- }
786
- interface ConfigToolOptions {
787
- /** Optional override for the config tool description. */
788
- description?: string;
789
- /** Initial config values when using the default in-memory store. */
790
- initial?: Record<string, unknown>;
791
- /** Custom config store implementation. */
792
- store?: ConfigStore;
793
- }
794
- declare function defineConfigTool(options?: ConfigToolOptions): ToolDefinition<ConfigToolInput, ConfigToolResponse>;
795
- interface QueryToolInput {
796
- cursor?: string | undefined;
797
- filters?: Record<string, unknown> | undefined;
798
- limit?: number | undefined;
799
- q?: string | undefined;
800
- query?: string | undefined;
801
- }
802
- interface QueryToolResponse<T = unknown> {
803
- _meta?: Record<string, unknown>;
804
- nextCursor?: string;
805
- results: T[];
806
- }
807
- interface QueryToolOptions<T = unknown> {
808
- /** Optional override for the query tool description. */
809
- description?: string;
810
- /** Custom query handler implementation. */
811
- handler?: (input: NormalizedQueryInput, ctx: HandlerContext2) => Promise<Result3<QueryToolResponse<T>, OutfitterError2>>;
812
- }
813
- declare function defineQueryTool<T = unknown>(options?: QueryToolOptions<T>): ToolDefinition<QueryToolInput, QueryToolResponse<T>>;
814
- interface CoreToolsOptions {
815
- config?: ConfigToolOptions;
816
- docs?: DocsToolOptions;
817
- query?: QueryToolOptions;
818
- }
819
- type NormalizedQueryInput = Required<Pick<QueryToolInput, "q">> & Omit<QueryToolInput, "q">;
820
- type CoreToolDefinition = ToolDefinition<DocsToolInput, DocsToolResponse> | ToolDefinition<ConfigToolInput, ConfigToolResponse> | ToolDefinition<QueryToolInput, QueryToolResponse>;
821
- declare function createCoreTools(options?: CoreToolsOptions): CoreToolDefinition[];
822
- import { JsonSchema, zodToJsonSchema } from "@outfitter/contracts/schema";
823
- import { OutfitterError as OutfitterError3 } from "@outfitter/contracts";
824
- /**
825
- * Create an MCP server instance.
826
- *
827
- * The server provides:
828
- * - Tool registration with Zod schema validation
829
- * - Resource registration
830
- * - Tool invocation with Result-based error handling
831
- * - Automatic error translation from OutfitterError to McpError
832
- *
833
- * @param options - Server configuration options
834
- * @returns Configured McpServer instance
835
- *
836
- * @example
837
- * ```typescript
838
- * const server = createMcpServer({
839
- * name: "calculator",
840
- * version: "1.0.0",
841
- * logger: createLogger({ name: "mcp" }),
842
- * });
843
- *
844
- * server.registerTool(defineTool({
845
- * name: "add",
846
- * description: "Add two numbers",
847
- * inputSchema: z.object({ a: z.number(), b: z.number() }),
848
- * handler: async (input) => Result.ok({ sum: input.a + input.b }),
849
- * }));
850
- *
851
- * const result = await server.invokeTool("add", { a: 2, b: 3 });
852
- * if (result.isOk()) {
853
- * console.log(result.value.sum); // 5
854
- * }
855
- * ```
856
- */
857
- declare function createMcpServer(options: McpServerOptions): McpServer;
858
- /**
859
- * Define a typed tool.
860
- *
861
- * This is a helper function that provides better type inference
862
- * when creating tool definitions.
863
- *
864
- * @param definition - Tool definition object
865
- * @returns The same tool definition with inferred types
866
- *
867
- * @example
868
- * ```typescript
869
- * const echoTool = defineTool({
870
- * name: "echo",
871
- * description: "Echo the input message",
872
- * inputSchema: z.object({ message: z.string() }),
873
- * handler: async (input, ctx) => {
874
- * ctx.logger.debug("Echoing message");
875
- * return Result.ok({ echo: input.message });
876
- * },
877
- * });
878
- * ```
879
- */
880
- declare function defineTool<
881
- TInput,
882
- TOutput,
883
- TError extends OutfitterError3 = OutfitterError3
884
- >(definition: ToolDefinition<TInput, TOutput, TError>): ToolDefinition<TInput, TOutput, TError>;
885
- /**
886
- * Define a resource.
887
- *
888
- * This is a helper function for creating resource definitions
889
- * with consistent typing.
890
- *
891
- * @param definition - Resource definition object
892
- * @returns The same resource definition
893
- *
894
- * @example
895
- * ```typescript
896
- * const configResource = defineResource({
897
- * uri: "file:///etc/app/config.json",
898
- * name: "Application Config",
899
- * description: "Main configuration file",
900
- * mimeType: "application/json",
901
- * });
902
- * ```
903
- */
904
- declare function defineResource(definition: ResourceDefinition): ResourceDefinition;
905
- /**
906
- * Define a resource template.
907
- *
908
- * Helper function for creating resource template definitions
909
- * with URI pattern matching.
910
- *
911
- * @param definition - Resource template definition object
912
- * @returns The same resource template definition
913
- */
914
- declare function defineResourceTemplate(definition: ResourceTemplateDefinition): ResourceTemplateDefinition;
915
- /**
916
- * Define a prompt.
917
- *
918
- * Helper function for creating prompt definitions
919
- * with consistent typing.
920
- *
921
- * @param definition - Prompt definition object
922
- * @returns The same prompt definition
923
- */
924
- declare function definePrompt(definition: PromptDefinition): PromptDefinition;
925
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
926
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
927
- import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
928
- type McpToolResponse = CallToolResult;
929
- /**
930
- * Wrap a handler success value into an MCP CallToolResult.
931
- *
932
- * If the value is already a valid McpToolResponse (has a `content` array),
933
- * it is returned as-is. Otherwise it is wrapped in a text content block.
934
- * Plain objects are also attached as `structuredContent` for SDK clients
935
- * that support structured output.
936
- */
937
- declare function wrapToolResult(value: unknown): McpToolResponse;
938
- /**
939
- * Wrap an error into an MCP CallToolResult with `isError: true`.
940
- *
941
- * Serializes the error (preserving `_tag`, `message`, `code`, `context` if
942
- * present) and wraps it as a text content block.
943
- */
944
- declare function wrapToolError(error: unknown): McpToolResponse;
945
- /**
946
- * Create an MCP SDK server from an Outfitter MCP server.
947
- */
948
- declare function createSdkServer(server: McpServer): Server;
949
- /**
950
- * Connect an MCP server over stdio transport.
951
- */
952
- declare function connectStdio(server: McpServer, transport?: StdioServerTransport): Promise<Server>;
953
- export { zodToJsonSchema, wrapToolResult, wrapToolError, shouldEmitLog, mapLogLevelToMcp, defineTool, defineResourceTemplate, defineResource, defineQueryTool, definePrompt, defineDocsTool, defineConfigTool, createSdkServer, createMcpServer, createCoreTools, connectStdio, buildMcpTools, adaptHandler, ToolDefinition, ToolAnnotations, TextResourceContent, TOOL_ANNOTATIONS, SerializedTool, ResourceTemplateReadHandler, ResourceTemplateDefinition, ResourceReadHandler, ResourceDefinition, ResourceContent, QueryToolResponse, QueryToolOptions, QueryToolInput, PromptResult, PromptMessageContent, PromptMessage, PromptHandler, PromptDefinition, PromptArgument, ProgressReporter, McpToolResponse, McpServerOptions, McpServer, McpLogLevel, McpHandlerContext, McpError, JsonSchema, InvokeToolOptions, DocsToolResponse, DocsToolOptions, DocsToolInput, DocsToolEntry, DocsSection, CoreToolsOptions, ContentAnnotations, ConfigToolResponse, ConfigToolOptions, ConfigToolInput, ConfigStore, ConfigAction, CompletionResult, CompletionRef, CompletionHandler, BuildMcpToolsOptions, BlobResourceContent };
1
+ import { McpToolResponse, connectStdio, createSdkServer, wrapToolError, wrapToolResult } from "./shared/@outfitter/mcp-yf0w5cgh.js";
2
+ import { McpNotificationSender, McpProgressNotification, createMcpProgressCallback } from "./shared/@outfitter/mcp-r27vbpc1.js";
3
+ import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-3hxaatj9.js";
4
+ import { BuildMcpToolsOptions, buildMcpTools } from "./shared/@outfitter/mcp-f67dnr72.js";
5
+ import { ConfigAction, ConfigStore, ConfigToolInput, ConfigToolOptions, ConfigToolResponse, CoreToolsOptions, DocsSection, DocsToolEntry, DocsToolInput, DocsToolOptions, DocsToolResponse, QueryToolInput, QueryToolOptions, QueryToolResponse, createCoreTools, defineConfigTool, defineDocsTool, defineQueryTool } from "./shared/@outfitter/mcp-4s22693j.js";
6
+ import "./shared/@outfitter/mcp-qmdmgxa1.js";
7
+ import { InvokeToolOptions, McpError, McpHandlerContext, McpServer, McpServerOptions, ProgressReporter, adaptHandler } from "./shared/@outfitter/mcp-7btcghjj.js";
8
+ import { SerializedTool, TOOL_ANNOTATIONS, ToolAnnotations, ToolDefinition } from "./shared/@outfitter/mcp-knc1gq0g.js";
9
+ import { BlobResourceContent, ResourceContent, ResourceDefinition, ResourceReadHandler, ResourceTemplateDefinition, ResourceTemplateReadHandler, TextResourceContent, TypedResourceTemplateDefinition, TypedResourceTemplateReadHandler } from "./shared/@outfitter/mcp-9ry52yg3.js";
10
+ import { CompletionHandler, CompletionRef, CompletionResult, PromptArgument, PromptDefinition, PromptHandler, PromptMessage, PromptMessageContent, PromptResult } from "./shared/@outfitter/mcp-dgwj3jna.js";
11
+ import { ContentAnnotations } from "./shared/@outfitter/mcp-q5hr7227.js";
12
+ import { McpLogLevel, mapLogLevelToMcp, shouldEmitLog } from "./shared/@outfitter/mcp-cqpyer9m.js";
13
+ import { JsonSchema, zodToJsonSchema } from "./shared/@outfitter/mcp-83zvbna8.js";
14
+ export { zodToJsonSchema, wrapToolResult, wrapToolError, shouldEmitLog, mapLogLevelToMcp, defineTool, defineResourceTemplate, defineResource, defineQueryTool, definePrompt, defineDocsTool, defineConfigTool, createSdkServer, createMcpServer, createMcpProgressCallback, createCoreTools, connectStdio, buildMcpTools, adaptHandler, TypedResourceTemplateReadHandler, TypedResourceTemplateDefinition, ToolDefinition, ToolAnnotations, TextResourceContent, TOOL_ANNOTATIONS, SerializedTool, ResourceTemplateReadHandler, ResourceTemplateDefinition, ResourceReadHandler, ResourceDefinition, ResourceContent, QueryToolResponse, QueryToolOptions, QueryToolInput, PromptResult, PromptMessageContent, PromptMessage, PromptHandler, PromptDefinition, PromptArgument, ProgressReporter, McpToolResponse, McpServerOptions, McpServer, McpProgressNotification, McpNotificationSender, McpLogLevel, McpHandlerContext, McpError, JsonSchema, InvokeToolOptions, DocsToolResponse, DocsToolOptions, DocsToolInput, DocsToolEntry, DocsSection, CoreToolsOptions, ContentAnnotations, ConfigToolResponse, ConfigToolOptions, ConfigToolInput, ConfigStore, ConfigAction, CompletionResult, CompletionRef, CompletionHandler, BuildMcpToolsOptions, BlobResourceContent };