@outfitter/mcp 0.2.0 → 0.4.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/README.md +179 -5
- package/dist/actions.d.ts +4 -0
- package/dist/actions.js +11 -0
- package/dist/core-tools.d.ts +4 -0
- package/dist/core-tools.js +13 -0
- package/dist/index.d.ts +140 -28
- package/dist/index.js +158 -51
- package/dist/logging.d.ts +2 -0
- package/dist/logging.js +9 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +7 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +18 -0
- package/dist/shared/@outfitter/mcp-2vqyt1fj.d.ts +104 -0
- package/dist/shared/@outfitter/mcp-9m5hs2z0.js +49 -0
- package/dist/shared/@outfitter/mcp-9whem1wr.js +28 -0
- package/dist/shared/@outfitter/mcp-a0cgfsnw.d.ts +8 -0
- package/dist/shared/@outfitter/mcp-cqpyer9m.d.ts +27 -0
- package/dist/shared/@outfitter/mcp-dwd800vf.d.ts +96 -0
- package/dist/shared/@outfitter/mcp-f91wbr49.js +341 -0
- package/dist/shared/@outfitter/mcp-fjtxsa0x.js +36 -0
- package/dist/shared/@outfitter/mcp-h2twz77x.d.ts +699 -0
- package/dist/shared/@outfitter/mcp-jk0ka9hw.d.ts +30 -0
- package/dist/shared/@outfitter/mcp-k8r6kefr.js +538 -0
- package/dist/shared/@outfitter/mcp-mzky3ck8.js +165 -0
- package/dist/shared/@outfitter/mcp-s80bqcsb.d.ts +60 -0
- package/dist/shared/@outfitter/mcp-zv3ej45k.js +143 -0
- package/dist/transport.d.ts +4 -0
- package/dist/transport.js +13 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +13 -0
- package/package.json +43 -7
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { McpLogLevel } from "./mcp-cqpyer9m";
|
|
2
|
+
import { Handler, HandlerContext, Logger, OutfitterError, Result, TaggedErrorClass } from "@outfitter/contracts";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { Result as Result2 } from "@outfitter/contracts";
|
|
5
|
+
import { TaggedError } from "@outfitter/contracts";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for creating an MCP server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const options: McpServerOptions = {
|
|
12
|
+
* name: "my-mcp-server",
|
|
13
|
+
* version: "1.0.0",
|
|
14
|
+
* logger: createLogger({ name: "mcp" }),
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* const server = createMcpServer(options);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface McpServerOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Server name, used in MCP protocol handshake.
|
|
23
|
+
* Should be a short, descriptive identifier.
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* Server version (semver format recommended).
|
|
28
|
+
* Sent to clients during initialization.
|
|
29
|
+
*/
|
|
30
|
+
version: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional logger instance for server logging.
|
|
33
|
+
* If not provided, the server uses the Outfitter logger factory defaults.
|
|
34
|
+
*/
|
|
35
|
+
logger?: Logger;
|
|
36
|
+
/**
|
|
37
|
+
* Default MCP log level for client-facing log forwarding.
|
|
38
|
+
*
|
|
39
|
+
* Precedence (highest wins):
|
|
40
|
+
* 1. `OUTFITTER_LOG_LEVEL` environment variable
|
|
41
|
+
* 2. This option
|
|
42
|
+
* 3. Environment profile (`OUTFITTER_ENV`)
|
|
43
|
+
* 4. `null` (no forwarding until client opts in)
|
|
44
|
+
*
|
|
45
|
+
* Set to `null` to explicitly disable forwarding regardless of environment.
|
|
46
|
+
* The MCP client can always override via `logging/setLevel`.
|
|
47
|
+
*/
|
|
48
|
+
defaultLogLevel?: McpLogLevel | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Behavioral hints for MCP tools.
|
|
52
|
+
*
|
|
53
|
+
* Annotations help clients understand tool behavior without invoking them.
|
|
54
|
+
* All fields are optional — only include hints that apply.
|
|
55
|
+
*
|
|
56
|
+
* @see https://spec.modelcontextprotocol.io/specification/2025-03-26/server/tools/#annotations
|
|
57
|
+
*/
|
|
58
|
+
interface ToolAnnotations {
|
|
59
|
+
/** When true, the tool does not modify any state. */
|
|
60
|
+
readOnlyHint?: boolean;
|
|
61
|
+
/** When true, the tool may perform destructive operations (e.g., deleting data). */
|
|
62
|
+
destructiveHint?: boolean;
|
|
63
|
+
/** When true, calling the tool multiple times with the same input has the same effect. */
|
|
64
|
+
idempotentHint?: boolean;
|
|
65
|
+
/** When true, the tool may interact with external systems beyond the server. */
|
|
66
|
+
openWorldHint?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Common annotation presets for MCP tools.
|
|
70
|
+
*
|
|
71
|
+
* Use these as a starting point and spread-override individual hints:
|
|
72
|
+
*
|
|
73
|
+
* ```typescript
|
|
74
|
+
* annotations: { ...TOOL_ANNOTATIONS.readOnly, openWorldHint: true }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* For multi-action tools (e.g., a single tool with read and write actions),
|
|
78
|
+
* use the most conservative union of hints — if any action is destructive,
|
|
79
|
+
* mark the whole tool as destructive. Per-action annotations are an MCP spec
|
|
80
|
+
* limitation; presets + spread cover most edge cases.
|
|
81
|
+
*/
|
|
82
|
+
declare const TOOL_ANNOTATIONS: {
|
|
83
|
+
/** Read-only, safe to call repeatedly. */
|
|
84
|
+
readonly readOnly: {
|
|
85
|
+
readonly readOnlyHint: true;
|
|
86
|
+
readonly destructiveHint: false;
|
|
87
|
+
readonly idempotentHint: true;
|
|
88
|
+
readonly openWorldHint: false;
|
|
89
|
+
};
|
|
90
|
+
/** Creates or updates state, not destructive. */
|
|
91
|
+
readonly write: {
|
|
92
|
+
readonly readOnlyHint: false;
|
|
93
|
+
readonly destructiveHint: false;
|
|
94
|
+
readonly idempotentHint: false;
|
|
95
|
+
readonly openWorldHint: false;
|
|
96
|
+
};
|
|
97
|
+
/** Idempotent write (PUT-like). */
|
|
98
|
+
readonly writeIdempotent: {
|
|
99
|
+
readonly readOnlyHint: false;
|
|
100
|
+
readonly destructiveHint: false;
|
|
101
|
+
readonly idempotentHint: true;
|
|
102
|
+
readonly openWorldHint: false;
|
|
103
|
+
};
|
|
104
|
+
/** Deletes or permanently modifies data. */
|
|
105
|
+
readonly destructive: {
|
|
106
|
+
readonly readOnlyHint: false;
|
|
107
|
+
readonly destructiveHint: true;
|
|
108
|
+
readonly idempotentHint: true;
|
|
109
|
+
readonly openWorldHint: false;
|
|
110
|
+
};
|
|
111
|
+
/** Interacts with external systems (APIs, network). */
|
|
112
|
+
readonly openWorld: {
|
|
113
|
+
readonly readOnlyHint: false;
|
|
114
|
+
readonly destructiveHint: false;
|
|
115
|
+
readonly idempotentHint: false;
|
|
116
|
+
readonly openWorldHint: true;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Definition of an MCP tool that can be invoked by clients.
|
|
121
|
+
*
|
|
122
|
+
* Tools are the primary way clients interact with MCP servers.
|
|
123
|
+
* Each tool has a name, description, input schema (for validation),
|
|
124
|
+
* and a handler function that processes requests.
|
|
125
|
+
*
|
|
126
|
+
* @typeParam TInput - The validated input type (inferred from Zod schema)
|
|
127
|
+
* @typeParam TOutput - The success output type
|
|
128
|
+
* @typeParam TError - The error type (must extend OutfitterError)
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const getUserTool: ToolDefinition<
|
|
133
|
+
* { userId: string },
|
|
134
|
+
* { name: string; email: string },
|
|
135
|
+
* NotFoundError
|
|
136
|
+
* > = {
|
|
137
|
+
* name: "get-user",
|
|
138
|
+
* description: "Retrieve a user by ID",
|
|
139
|
+
* inputSchema: z.object({ userId: z.string().uuid() }),
|
|
140
|
+
* handler: async (input, ctx) => {
|
|
141
|
+
* ctx.logger.debug("Fetching user", { userId: input.userId });
|
|
142
|
+
* const user = await db.users.find(input.userId);
|
|
143
|
+
* if (!user) {
|
|
144
|
+
* return Result.err(new NotFoundError({
|
|
145
|
+
* message: `User ${input.userId} not found`,
|
|
146
|
+
* resourceType: "user",
|
|
147
|
+
* resourceId: input.userId,
|
|
148
|
+
* }));
|
|
149
|
+
* }
|
|
150
|
+
* return Result.ok({ name: user.name, email: user.email });
|
|
151
|
+
* },
|
|
152
|
+
* };
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
interface ToolDefinition<
|
|
156
|
+
TInput,
|
|
157
|
+
TOutput,
|
|
158
|
+
TError extends OutfitterError = OutfitterError
|
|
159
|
+
> {
|
|
160
|
+
/**
|
|
161
|
+
* Unique tool name (kebab-case recommended).
|
|
162
|
+
* Used by clients to invoke the tool.
|
|
163
|
+
*/
|
|
164
|
+
name: string;
|
|
165
|
+
/**
|
|
166
|
+
* Human-readable description of what the tool does.
|
|
167
|
+
* Shown to clients and used by LLMs to understand tool capabilities.
|
|
168
|
+
*/
|
|
169
|
+
description: string;
|
|
170
|
+
/**
|
|
171
|
+
* Whether the tool should be deferred for tool search.
|
|
172
|
+
* Defaults to true for domain tools; core tools set this to false.
|
|
173
|
+
*/
|
|
174
|
+
deferLoading?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Zod schema for validating and parsing input.
|
|
177
|
+
* The schema defines the expected input structure.
|
|
178
|
+
*/
|
|
179
|
+
inputSchema: z.ZodType<TInput>;
|
|
180
|
+
/**
|
|
181
|
+
* Optional behavioral annotations for the tool.
|
|
182
|
+
* Helps clients understand tool behavior without invoking it.
|
|
183
|
+
*/
|
|
184
|
+
annotations?: ToolAnnotations;
|
|
185
|
+
/**
|
|
186
|
+
* Handler function that processes the tool invocation.
|
|
187
|
+
* Receives validated input and HandlerContext, returns Result.
|
|
188
|
+
*/
|
|
189
|
+
handler: Handler<TInput, TOutput, TError>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Serialized tool information for MCP protocol.
|
|
193
|
+
* This is the format sent to clients during tool listing.
|
|
194
|
+
*/
|
|
195
|
+
interface SerializedTool {
|
|
196
|
+
/** Tool name */
|
|
197
|
+
name: string;
|
|
198
|
+
/** Tool description */
|
|
199
|
+
description: string;
|
|
200
|
+
/** JSON Schema representation of the input schema */
|
|
201
|
+
inputSchema: Record<string, unknown>;
|
|
202
|
+
/** MCP tool-search hint: whether tool is deferred */
|
|
203
|
+
defer_loading?: boolean;
|
|
204
|
+
/** Behavioral annotations for the tool */
|
|
205
|
+
annotations?: ToolAnnotations;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Annotations for content items (resource content, prompt messages).
|
|
209
|
+
*
|
|
210
|
+
* Provides hints about content audience and priority.
|
|
211
|
+
*
|
|
212
|
+
* @see https://spec.modelcontextprotocol.io/specification/2025-03-26/server/utilities/annotations/
|
|
213
|
+
*/
|
|
214
|
+
interface ContentAnnotations {
|
|
215
|
+
/**
|
|
216
|
+
* Who the content is intended for.
|
|
217
|
+
* Can include "user", "assistant", or both.
|
|
218
|
+
*/
|
|
219
|
+
audience?: Array<"user" | "assistant">;
|
|
220
|
+
/**
|
|
221
|
+
* Priority level from 0.0 (least) to 1.0 (most important).
|
|
222
|
+
*/
|
|
223
|
+
priority?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Text content returned from a resource read.
|
|
227
|
+
*/
|
|
228
|
+
interface TextResourceContent {
|
|
229
|
+
/** Resource URI */
|
|
230
|
+
uri: string;
|
|
231
|
+
/** Text content */
|
|
232
|
+
text: string;
|
|
233
|
+
/** Optional MIME type */
|
|
234
|
+
mimeType?: string;
|
|
235
|
+
/** Optional content annotations */
|
|
236
|
+
annotations?: ContentAnnotations;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Binary (base64-encoded) content returned from a resource read.
|
|
240
|
+
*/
|
|
241
|
+
interface BlobResourceContent {
|
|
242
|
+
/** Resource URI */
|
|
243
|
+
uri: string;
|
|
244
|
+
/** Base64-encoded binary content */
|
|
245
|
+
blob: string;
|
|
246
|
+
/** Optional MIME type */
|
|
247
|
+
mimeType?: string;
|
|
248
|
+
/** Optional content annotations */
|
|
249
|
+
annotations?: ContentAnnotations;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Content returned from reading a resource.
|
|
253
|
+
*/
|
|
254
|
+
type ResourceContent = TextResourceContent | BlobResourceContent;
|
|
255
|
+
/**
|
|
256
|
+
* Handler for reading a resource's content.
|
|
257
|
+
*
|
|
258
|
+
* @param uri - The resource URI being read
|
|
259
|
+
* @param ctx - Handler context with logger and requestId
|
|
260
|
+
* @returns Array of resource content items
|
|
261
|
+
*/
|
|
262
|
+
type ResourceReadHandler = (uri: string, ctx: HandlerContext) => Promise<Result<ResourceContent[], OutfitterError>>;
|
|
263
|
+
/**
|
|
264
|
+
* Definition of an MCP resource that can be read by clients.
|
|
265
|
+
*
|
|
266
|
+
* Resources represent data that clients can access, such as files,
|
|
267
|
+
* database records, or API responses.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const configResource: ResourceDefinition = {
|
|
272
|
+
* uri: "file:///etc/app/config.json",
|
|
273
|
+
* name: "Application Config",
|
|
274
|
+
* description: "Main application configuration file",
|
|
275
|
+
* mimeType: "application/json",
|
|
276
|
+
* handler: async (uri, ctx) => {
|
|
277
|
+
* const content = await readFile(uri);
|
|
278
|
+
* return Result.ok([{ uri, text: content }]);
|
|
279
|
+
* },
|
|
280
|
+
* };
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
interface ResourceDefinition {
|
|
284
|
+
/**
|
|
285
|
+
* Unique resource URI.
|
|
286
|
+
* Must be a valid URI (file://, https://, custom://, etc.).
|
|
287
|
+
*/
|
|
288
|
+
uri: string;
|
|
289
|
+
/**
|
|
290
|
+
* Human-readable resource name.
|
|
291
|
+
* Displayed to users in resource listings.
|
|
292
|
+
*/
|
|
293
|
+
name: string;
|
|
294
|
+
/**
|
|
295
|
+
* Optional description of the resource.
|
|
296
|
+
* Provides additional context about the resource contents.
|
|
297
|
+
*/
|
|
298
|
+
description?: string;
|
|
299
|
+
/**
|
|
300
|
+
* Optional MIME type of the resource content.
|
|
301
|
+
* Helps clients understand how to process the resource.
|
|
302
|
+
*/
|
|
303
|
+
mimeType?: string;
|
|
304
|
+
/**
|
|
305
|
+
* Optional handler for reading the resource content.
|
|
306
|
+
* If not provided, the resource is metadata-only.
|
|
307
|
+
*/
|
|
308
|
+
handler?: ResourceReadHandler;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Handler for reading a resource template's content.
|
|
312
|
+
*
|
|
313
|
+
* @param uri - The matched URI
|
|
314
|
+
* @param variables - Extracted template variables
|
|
315
|
+
* @param ctx - Handler context
|
|
316
|
+
*/
|
|
317
|
+
type ResourceTemplateReadHandler = (uri: string, variables: Record<string, string>, ctx: HandlerContext) => Promise<Result<ResourceContent[], OutfitterError>>;
|
|
318
|
+
/**
|
|
319
|
+
* Definition of an MCP resource template with URI pattern matching.
|
|
320
|
+
*
|
|
321
|
+
* Templates use RFC 6570 Level 1 URI templates (e.g., `{param}`)
|
|
322
|
+
* to match and extract variables from URIs.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const userTemplate: ResourceTemplateDefinition = {
|
|
327
|
+
* uriTemplate: "db:///users/{userId}/profile",
|
|
328
|
+
* name: "User Profile",
|
|
329
|
+
* handler: async (uri, variables) => {
|
|
330
|
+
* const profile = await getProfile(variables.userId);
|
|
331
|
+
* return Result.ok([{ uri, text: JSON.stringify(profile) }]);
|
|
332
|
+
* },
|
|
333
|
+
* };
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
interface ResourceTemplateDefinition {
|
|
337
|
+
/** URI template with `{param}` placeholders (RFC 6570 Level 1). */
|
|
338
|
+
uriTemplate: string;
|
|
339
|
+
/** Human-readable name for the template. */
|
|
340
|
+
name: string;
|
|
341
|
+
/** Optional description. */
|
|
342
|
+
description?: string;
|
|
343
|
+
/** Optional MIME type. */
|
|
344
|
+
mimeType?: string;
|
|
345
|
+
/** Optional completion handlers keyed by parameter name. */
|
|
346
|
+
complete?: Record<string, CompletionHandler>;
|
|
347
|
+
/** Handler for reading matched resources. */
|
|
348
|
+
handler: ResourceTemplateReadHandler;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Result of a completion request.
|
|
352
|
+
*/
|
|
353
|
+
interface CompletionResult {
|
|
354
|
+
/** Completion values */
|
|
355
|
+
values: string[];
|
|
356
|
+
/** Total number of available values (for pagination) */
|
|
357
|
+
total?: number;
|
|
358
|
+
/** Whether there are more values */
|
|
359
|
+
hasMore?: boolean;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Handler for generating completions.
|
|
363
|
+
*/
|
|
364
|
+
type CompletionHandler = (value: string) => Promise<CompletionResult>;
|
|
365
|
+
/**
|
|
366
|
+
* Reference to a prompt or resource for completion.
|
|
367
|
+
*/
|
|
368
|
+
type CompletionRef = {
|
|
369
|
+
type: "ref/prompt";
|
|
370
|
+
name: string;
|
|
371
|
+
} | {
|
|
372
|
+
type: "ref/resource";
|
|
373
|
+
uri: string;
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Argument definition for a prompt.
|
|
377
|
+
*/
|
|
378
|
+
interface PromptArgument {
|
|
379
|
+
/** Argument name */
|
|
380
|
+
name: string;
|
|
381
|
+
/** Human-readable description */
|
|
382
|
+
description?: string;
|
|
383
|
+
/** Whether this argument is required */
|
|
384
|
+
required?: boolean;
|
|
385
|
+
/** Optional completion handler for this argument */
|
|
386
|
+
complete?: CompletionHandler;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Content block within a prompt message.
|
|
390
|
+
*/
|
|
391
|
+
interface PromptMessageContent {
|
|
392
|
+
/** Content type */
|
|
393
|
+
type: "text";
|
|
394
|
+
/** Text content */
|
|
395
|
+
text: string;
|
|
396
|
+
/** Optional content annotations */
|
|
397
|
+
annotations?: ContentAnnotations;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* A message in a prompt response.
|
|
401
|
+
*/
|
|
402
|
+
interface PromptMessage {
|
|
403
|
+
/** Message role */
|
|
404
|
+
role: "user" | "assistant";
|
|
405
|
+
/** Message content */
|
|
406
|
+
content: PromptMessageContent;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Result returned from getting a prompt.
|
|
410
|
+
*/
|
|
411
|
+
interface PromptResult {
|
|
412
|
+
/** Prompt messages */
|
|
413
|
+
messages: PromptMessage[];
|
|
414
|
+
/** Optional description override */
|
|
415
|
+
description?: string;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Handler for generating prompt messages.
|
|
419
|
+
*/
|
|
420
|
+
type PromptHandler = (args: Record<string, string | undefined>) => Promise<Result<PromptResult, OutfitterError>>;
|
|
421
|
+
/**
|
|
422
|
+
* Definition of an MCP prompt.
|
|
423
|
+
*
|
|
424
|
+
* Prompts are reusable templates that generate messages for LLMs.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const reviewPrompt: PromptDefinition = {
|
|
429
|
+
* name: "code-review",
|
|
430
|
+
* description: "Review code changes",
|
|
431
|
+
* arguments: [
|
|
432
|
+
* { name: "language", description: "Programming language", required: true },
|
|
433
|
+
* ],
|
|
434
|
+
* handler: async (args) => Result.ok({
|
|
435
|
+
* messages: [{ role: "user", content: { type: "text", text: `Review this ${args.language} code` } }],
|
|
436
|
+
* }),
|
|
437
|
+
* };
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
interface PromptDefinition {
|
|
441
|
+
/** Unique prompt name */
|
|
442
|
+
name: string;
|
|
443
|
+
/** Human-readable description */
|
|
444
|
+
description?: string;
|
|
445
|
+
/** Prompt arguments */
|
|
446
|
+
arguments: PromptArgument[];
|
|
447
|
+
/** Handler to generate messages */
|
|
448
|
+
handler: PromptHandler;
|
|
449
|
+
}
|
|
450
|
+
declare const McpErrorBase: TaggedErrorClass<"McpError", {
|
|
451
|
+
message: string;
|
|
452
|
+
code: number;
|
|
453
|
+
context?: Record<string, unknown>;
|
|
454
|
+
}>;
|
|
455
|
+
/**
|
|
456
|
+
* MCP-specific error with JSON-RPC error code.
|
|
457
|
+
*
|
|
458
|
+
* Used when tool invocations fail or when there are protocol-level errors.
|
|
459
|
+
* Follows the JSON-RPC 2.0 error object format.
|
|
460
|
+
*
|
|
461
|
+
* Standard error codes:
|
|
462
|
+
* - `-32700`: Parse error
|
|
463
|
+
* - `-32600`: Invalid request
|
|
464
|
+
* - `-32601`: Method not found
|
|
465
|
+
* - `-32602`: Invalid params
|
|
466
|
+
* - `-32603`: Internal error
|
|
467
|
+
* - `-32000` to `-32099`: Server errors (reserved)
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* const error = new McpError({
|
|
472
|
+
* message: "Tool not found: unknown-tool",
|
|
473
|
+
* code: -32601,
|
|
474
|
+
* context: { tool: "unknown-tool" },
|
|
475
|
+
* });
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
declare class McpError extends McpErrorBase {
|
|
479
|
+
/** Error category for Outfitter error taxonomy compatibility */
|
|
480
|
+
readonly category: "internal";
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Options for invoking a tool.
|
|
484
|
+
*/
|
|
485
|
+
interface InvokeToolOptions {
|
|
486
|
+
/** Abort signal for cancellation */
|
|
487
|
+
signal?: AbortSignal;
|
|
488
|
+
/** Custom request ID (auto-generated if not provided) */
|
|
489
|
+
requestId?: string;
|
|
490
|
+
/** Progress token from client for tracking progress */
|
|
491
|
+
progressToken?: string | number;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* MCP Server instance.
|
|
495
|
+
*
|
|
496
|
+
* Provides methods for registering tools and resources, and for
|
|
497
|
+
* starting/stopping the server.
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* const server = createMcpServer({
|
|
502
|
+
* name: "my-server",
|
|
503
|
+
* version: "1.0.0",
|
|
504
|
+
* });
|
|
505
|
+
*
|
|
506
|
+
* server.registerTool(myTool);
|
|
507
|
+
* server.registerResource(myResource);
|
|
508
|
+
*
|
|
509
|
+
* await server.start();
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
interface McpServer {
|
|
513
|
+
/** Server name */
|
|
514
|
+
readonly name: string;
|
|
515
|
+
/** Server version */
|
|
516
|
+
readonly version: string;
|
|
517
|
+
/**
|
|
518
|
+
* Register a tool with the server.
|
|
519
|
+
* @param tool - Tool definition to register
|
|
520
|
+
*/
|
|
521
|
+
registerTool<
|
|
522
|
+
TInput,
|
|
523
|
+
TOutput,
|
|
524
|
+
TError extends OutfitterError
|
|
525
|
+
>(tool: ToolDefinition<TInput, TOutput, TError>): void;
|
|
526
|
+
/**
|
|
527
|
+
* Register a resource with the server.
|
|
528
|
+
* @param resource - Resource definition to register
|
|
529
|
+
*/
|
|
530
|
+
registerResource(resource: ResourceDefinition): void;
|
|
531
|
+
/**
|
|
532
|
+
* Get all registered tools.
|
|
533
|
+
* @returns Array of serialized tool information
|
|
534
|
+
*/
|
|
535
|
+
getTools(): SerializedTool[];
|
|
536
|
+
/**
|
|
537
|
+
* Register a resource template with the server.
|
|
538
|
+
* @param template - Resource template definition to register
|
|
539
|
+
*/
|
|
540
|
+
registerResourceTemplate(template: ResourceTemplateDefinition): void;
|
|
541
|
+
/**
|
|
542
|
+
* Get all registered resources.
|
|
543
|
+
* @returns Array of resource definitions
|
|
544
|
+
*/
|
|
545
|
+
getResources(): ResourceDefinition[];
|
|
546
|
+
/**
|
|
547
|
+
* Get all registered resource templates.
|
|
548
|
+
* @returns Array of resource template definitions
|
|
549
|
+
*/
|
|
550
|
+
getResourceTemplates(): ResourceTemplateDefinition[];
|
|
551
|
+
/**
|
|
552
|
+
* Complete an argument value.
|
|
553
|
+
* @param ref - Reference to the prompt or resource template
|
|
554
|
+
* @param argumentName - Name of the argument to complete
|
|
555
|
+
* @param value - Current value to complete
|
|
556
|
+
* @returns Result with completion values or McpError
|
|
557
|
+
*/
|
|
558
|
+
complete(ref: CompletionRef, argumentName: string, value: string): Promise<Result<CompletionResult, InstanceType<typeof McpError>>>;
|
|
559
|
+
/**
|
|
560
|
+
* Register a prompt with the server.
|
|
561
|
+
* @param prompt - Prompt definition to register
|
|
562
|
+
*/
|
|
563
|
+
registerPrompt(prompt: PromptDefinition): void;
|
|
564
|
+
/**
|
|
565
|
+
* Get all registered prompts.
|
|
566
|
+
* @returns Array of prompt definitions (without handlers)
|
|
567
|
+
*/
|
|
568
|
+
getPrompts(): Array<{
|
|
569
|
+
name: string;
|
|
570
|
+
description?: string;
|
|
571
|
+
arguments: PromptArgument[];
|
|
572
|
+
}>;
|
|
573
|
+
/**
|
|
574
|
+
* Get a specific prompt's messages.
|
|
575
|
+
* @param name - Prompt name
|
|
576
|
+
* @param args - Prompt arguments
|
|
577
|
+
* @returns Result with prompt result or McpError
|
|
578
|
+
*/
|
|
579
|
+
getPrompt(name: string, args: Record<string, string | undefined>): Promise<Result<PromptResult, InstanceType<typeof McpError>>>;
|
|
580
|
+
/**
|
|
581
|
+
* Read a resource by URI.
|
|
582
|
+
* @param uri - Resource URI
|
|
583
|
+
* @returns Result with resource content or McpError
|
|
584
|
+
*/
|
|
585
|
+
readResource(uri: string): Promise<Result<ResourceContent[], InstanceType<typeof McpError>>>;
|
|
586
|
+
/**
|
|
587
|
+
* Invoke a tool by name.
|
|
588
|
+
* @param name - Tool name
|
|
589
|
+
* @param input - Tool input (will be validated)
|
|
590
|
+
* @param options - Optional invocation options
|
|
591
|
+
* @returns Result with tool output or McpError
|
|
592
|
+
*/
|
|
593
|
+
invokeTool<T = unknown>(name: string, input: unknown, options?: InvokeToolOptions): Promise<Result<T, InstanceType<typeof McpError>>>;
|
|
594
|
+
/**
|
|
595
|
+
* Subscribe to updates for a resource URI.
|
|
596
|
+
* @param uri - Resource URI to subscribe to
|
|
597
|
+
*/
|
|
598
|
+
subscribe(uri: string): void;
|
|
599
|
+
/**
|
|
600
|
+
* Unsubscribe from updates for a resource URI.
|
|
601
|
+
* @param uri - Resource URI to unsubscribe from
|
|
602
|
+
*/
|
|
603
|
+
unsubscribe(uri: string): void;
|
|
604
|
+
/**
|
|
605
|
+
* Notify connected clients that a specific resource has been updated.
|
|
606
|
+
* Only emits for subscribed URIs.
|
|
607
|
+
* @param uri - URI of the updated resource
|
|
608
|
+
*/
|
|
609
|
+
notifyResourceUpdated(uri: string): void;
|
|
610
|
+
/**
|
|
611
|
+
* Notify connected clients that the tool list has changed.
|
|
612
|
+
*/
|
|
613
|
+
notifyToolsChanged(): void;
|
|
614
|
+
/**
|
|
615
|
+
* Notify connected clients that the resource list has changed.
|
|
616
|
+
*/
|
|
617
|
+
notifyResourcesChanged(): void;
|
|
618
|
+
/**
|
|
619
|
+
* Notify connected clients that the prompt list has changed.
|
|
620
|
+
*/
|
|
621
|
+
notifyPromptsChanged(): void;
|
|
622
|
+
/**
|
|
623
|
+
* Set the client-requested log level.
|
|
624
|
+
* Only log messages at or above this level will be forwarded.
|
|
625
|
+
* @param level - MCP log level string
|
|
626
|
+
*/
|
|
627
|
+
setLogLevel?(level: string): void;
|
|
628
|
+
/**
|
|
629
|
+
* Send a log message to connected clients.
|
|
630
|
+
* Filters by the client-requested log level threshold.
|
|
631
|
+
* No-op if no SDK server is bound or if the message is below the threshold.
|
|
632
|
+
*
|
|
633
|
+
* @param level - MCP log level for the message
|
|
634
|
+
* @param data - Log data (string, object, or any serializable value)
|
|
635
|
+
* @param loggerName - Optional logger name for client-side filtering
|
|
636
|
+
*/
|
|
637
|
+
sendLogMessage(level: McpLogLevel, data: unknown, loggerName?: string): void;
|
|
638
|
+
/**
|
|
639
|
+
* Bind the SDK server instance for notifications.
|
|
640
|
+
* Called internally by the transport layer.
|
|
641
|
+
* @param sdkServer - The MCP SDK Server instance
|
|
642
|
+
*/
|
|
643
|
+
bindSdkServer?(sdkServer: any): void;
|
|
644
|
+
/**
|
|
645
|
+
* Start the MCP server.
|
|
646
|
+
* Begins listening for client connections.
|
|
647
|
+
*/
|
|
648
|
+
start(): Promise<void>;
|
|
649
|
+
/**
|
|
650
|
+
* Stop the MCP server.
|
|
651
|
+
* Closes all connections and cleans up resources.
|
|
652
|
+
*/
|
|
653
|
+
stop(): Promise<void>;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Reporter for sending progress updates to clients.
|
|
657
|
+
*/
|
|
658
|
+
interface ProgressReporter {
|
|
659
|
+
/**
|
|
660
|
+
* Report progress for the current operation.
|
|
661
|
+
* @param progress - Current progress value
|
|
662
|
+
* @param total - Optional total value (for percentage calculation)
|
|
663
|
+
* @param message - Optional human-readable status message
|
|
664
|
+
*/
|
|
665
|
+
report(progress: number, total?: number, message?: string): void;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Extended handler context for MCP tools.
|
|
669
|
+
* Includes MCP-specific information in addition to standard HandlerContext.
|
|
670
|
+
*/
|
|
671
|
+
interface McpHandlerContext extends HandlerContext {
|
|
672
|
+
/** The name of the tool being invoked */
|
|
673
|
+
toolName?: string;
|
|
674
|
+
/** Progress reporter, present when client provides a progressToken */
|
|
675
|
+
progress?: ProgressReporter;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Adapt a handler with a domain error type for use with MCP tools.
|
|
679
|
+
*
|
|
680
|
+
* MCP tool definitions constrain `TError extends OutfitterError`. When your
|
|
681
|
+
* handler returns domain-specific errors that extend `Error` but not
|
|
682
|
+
* `OutfitterError`, use this function instead of an unsafe cast:
|
|
683
|
+
*
|
|
684
|
+
* ```typescript
|
|
685
|
+
* import { adaptHandler } from "@outfitter/mcp";
|
|
686
|
+
*
|
|
687
|
+
* const tool = defineTool({
|
|
688
|
+
* name: "my-tool",
|
|
689
|
+
* inputSchema: z.object({ id: z.string() }),
|
|
690
|
+
* handler: adaptHandler(myDomainHandler),
|
|
691
|
+
* });
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
declare function adaptHandler<
|
|
695
|
+
TInput,
|
|
696
|
+
TOutput,
|
|
697
|
+
TError extends Error
|
|
698
|
+
>(handler: (input: TInput, ctx: HandlerContext) => Promise<Result<TOutput, TError>>): Handler<TInput, TOutput, OutfitterError>;
|
|
699
|
+
export { McpServerOptions, ToolAnnotations, TOOL_ANNOTATIONS, ToolDefinition, SerializedTool, ContentAnnotations, TextResourceContent, BlobResourceContent, ResourceContent, ResourceReadHandler, ResourceDefinition, ResourceTemplateReadHandler, ResourceTemplateDefinition, CompletionResult, CompletionHandler, CompletionRef, PromptArgument, PromptMessageContent, PromptMessage, PromptResult, PromptHandler, PromptDefinition, McpError, InvokeToolOptions, McpServer, ProgressReporter, McpHandlerContext, adaptHandler, Result2 as Result, TaggedError };
|