@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.
- package/README.md +130 -28
- package/dist/actions.d.ts +7 -2
- package/dist/actions.js +52 -5
- package/dist/core-tools.d.ts +7 -2
- package/dist/core-tools.js +140 -6
- package/dist/index.d.ts +14 -953
- package/dist/index.js +8 -959
- package/dist/internal/content-types.d.ts +2 -0
- package/dist/internal/content-types.js +1 -0
- package/dist/internal/log-config.d.ts +24 -0
- package/dist/internal/log-config.js +13 -0
- package/dist/internal/prompt-types.d.ts +3 -0
- package/dist/internal/prompt-types.js +1 -0
- package/dist/internal/resource-types.d.ts +4 -0
- package/dist/internal/resource-types.js +1 -0
- package/dist/internal/server-types.d.ts +7 -0
- package/dist/internal/server-types.js +20 -0
- package/dist/internal/tool-types.d.ts +2 -0
- package/dist/{shared/@outfitter/mcp-9m5hs2z0.js → internal/tool-types.js} +4 -16
- package/dist/internal/uri-template.d.ts +8 -0
- package/dist/internal/uri-template.js +7 -0
- package/dist/progress.d.ts +2 -0
- package/dist/progress.js +7 -0
- package/dist/schema.js +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -3
- package/dist/shared/@outfitter/{mcp-5b5726ga.d.ts → mcp-3hxaatj9.d.ts} +37 -6
- package/dist/shared/@outfitter/{mcp-zb3p61y9.d.ts → mcp-4s22693j.d.ts} +1 -1
- package/dist/shared/@outfitter/mcp-7btcghjj.d.ts +304 -0
- package/dist/shared/@outfitter/mcp-9ry52yg3.d.ts +187 -0
- package/dist/shared/@outfitter/mcp-dgwj3jna.d.ts +103 -0
- package/dist/shared/@outfitter/{mcp-5jcgb033.d.ts → mcp-f67dnr72.d.ts} +1 -1
- package/dist/shared/@outfitter/mcp-hw5wz4gb.js +1 -0
- package/dist/shared/@outfitter/mcp-knc1gq0g.d.ts +130 -0
- package/dist/shared/@outfitter/mcp-n9vzcp37.js +55 -0
- package/dist/shared/@outfitter/mcp-q5hr7227.d.ts +24 -0
- package/dist/shared/@outfitter/mcp-q70dtfj6.js +53 -0
- package/dist/shared/@outfitter/mcp-r27vbpc1.d.ts +45 -0
- package/dist/shared/@outfitter/mcp-s2vnhzav.js +2 -0
- package/dist/shared/@outfitter/{mcp-s3gfhcdk.d.ts → mcp-yf0w5cgh.d.ts} +1 -1
- package/dist/shared/@outfitter/{mcp-hh12tqfg.js → mcp-yf1n85e9.js} +79 -119
- package/dist/shared/@outfitter/mcp-zt2s3r38.js +33 -0
- package/dist/transport.d.ts +7 -2
- package/dist/transport.js +161 -5
- package/dist/types.d.ts +7 -2
- package/dist/types.js +1 -1
- package/package.json +33 -27
- package/dist/shared/@outfitter/mcp-fks4zt1z.d.ts +0 -699
- package/dist/shared/@outfitter/mcp-mzky3ck8.js +0 -165
- package/dist/shared/@outfitter/mcp-zmc7ht6z.js +0 -28
- package/dist/shared/@outfitter/mcp-zv3ej45k.js +0 -143
- package/dist/shared/@outfitter/mcp-zy7b487d.js +0 -5
|
@@ -1,699 +0,0 @@
|
|
|
1
|
-
import { McpLogLevel } from "./mcp-cqpyer9m.js";
|
|
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
|
-
* Default MCP log level for client-facing log forwarding.
|
|
23
|
-
*
|
|
24
|
-
* Precedence (highest wins):
|
|
25
|
-
* 1. `OUTFITTER_LOG_LEVEL` environment variable
|
|
26
|
-
* 2. This option
|
|
27
|
-
* 3. Environment profile (`OUTFITTER_ENV`)
|
|
28
|
-
* 4. `null` (no forwarding until client opts in)
|
|
29
|
-
*
|
|
30
|
-
* Set to `null` to explicitly disable forwarding regardless of environment.
|
|
31
|
-
* The MCP client can always override via `logging/setLevel`.
|
|
32
|
-
*/
|
|
33
|
-
defaultLogLevel?: McpLogLevel | null;
|
|
34
|
-
/**
|
|
35
|
-
* Optional logger instance for server logging.
|
|
36
|
-
* If not provided, the server uses the Outfitter logger factory defaults.
|
|
37
|
-
*/
|
|
38
|
-
logger?: Logger;
|
|
39
|
-
/**
|
|
40
|
-
* Server name, used in MCP protocol handshake.
|
|
41
|
-
* Should be a short, descriptive identifier.
|
|
42
|
-
*/
|
|
43
|
-
name: string;
|
|
44
|
-
/**
|
|
45
|
-
* Server version (semver format recommended).
|
|
46
|
-
* Sent to clients during initialization.
|
|
47
|
-
*/
|
|
48
|
-
version: string;
|
|
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 may perform destructive operations (e.g., deleting data). */
|
|
60
|
-
destructiveHint?: boolean;
|
|
61
|
-
/** When true, calling the tool multiple times with the same input has the same effect. */
|
|
62
|
-
idempotentHint?: boolean;
|
|
63
|
-
/** When true, the tool may interact with external systems beyond the server. */
|
|
64
|
-
openWorldHint?: boolean;
|
|
65
|
-
/** When true, the tool does not modify any state. */
|
|
66
|
-
readOnlyHint?: 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
|
-
* Optional behavioral annotations for the tool.
|
|
162
|
-
* Helps clients understand tool behavior without invoking it.
|
|
163
|
-
*/
|
|
164
|
-
annotations?: ToolAnnotations;
|
|
165
|
-
/**
|
|
166
|
-
* Whether the tool should be deferred for tool search.
|
|
167
|
-
* Defaults to true for domain tools; core tools set this to false.
|
|
168
|
-
*/
|
|
169
|
-
deferLoading?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Human-readable description of what the tool does.
|
|
172
|
-
* Shown to clients and used by LLMs to understand tool capabilities.
|
|
173
|
-
*/
|
|
174
|
-
description: string;
|
|
175
|
-
/**
|
|
176
|
-
* Handler function that processes the tool invocation.
|
|
177
|
-
* Receives validated input and HandlerContext, returns Result.
|
|
178
|
-
*/
|
|
179
|
-
handler: Handler<TInput, TOutput, TError>;
|
|
180
|
-
/**
|
|
181
|
-
* Zod schema for validating and parsing input.
|
|
182
|
-
* The schema defines the expected input structure.
|
|
183
|
-
*/
|
|
184
|
-
inputSchema: z.ZodType<TInput>;
|
|
185
|
-
/**
|
|
186
|
-
* Unique tool name (kebab-case recommended).
|
|
187
|
-
* Used by clients to invoke the tool.
|
|
188
|
-
*/
|
|
189
|
-
name: string;
|
|
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
|
-
/** Behavioral annotations for the tool */
|
|
197
|
-
annotations?: ToolAnnotations;
|
|
198
|
-
/** MCP tool-search hint: whether tool is deferred */
|
|
199
|
-
defer_loading?: boolean;
|
|
200
|
-
/** Tool description */
|
|
201
|
-
description: string;
|
|
202
|
-
/** JSON Schema representation of the input schema */
|
|
203
|
-
inputSchema: Record<string, unknown>;
|
|
204
|
-
/** Tool name */
|
|
205
|
-
name: string;
|
|
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
|
-
/** Optional content annotations */
|
|
230
|
-
annotations?: ContentAnnotations;
|
|
231
|
-
/** Optional MIME type */
|
|
232
|
-
mimeType?: string;
|
|
233
|
-
/** Text content */
|
|
234
|
-
text: string;
|
|
235
|
-
/** Resource URI */
|
|
236
|
-
uri: string;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Binary (base64-encoded) content returned from a resource read.
|
|
240
|
-
*/
|
|
241
|
-
interface BlobResourceContent {
|
|
242
|
-
/** Optional content annotations */
|
|
243
|
-
annotations?: ContentAnnotations;
|
|
244
|
-
/** Base64-encoded binary content */
|
|
245
|
-
blob: string;
|
|
246
|
-
/** Optional MIME type */
|
|
247
|
-
mimeType?: string;
|
|
248
|
-
/** Resource URI */
|
|
249
|
-
uri: string;
|
|
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
|
-
* Optional description of the resource.
|
|
286
|
-
* Provides additional context about the resource contents.
|
|
287
|
-
*/
|
|
288
|
-
description?: string;
|
|
289
|
-
/**
|
|
290
|
-
* Optional handler for reading the resource content.
|
|
291
|
-
* If not provided, the resource is metadata-only.
|
|
292
|
-
*/
|
|
293
|
-
handler?: ResourceReadHandler;
|
|
294
|
-
/**
|
|
295
|
-
* Optional MIME type of the resource content.
|
|
296
|
-
* Helps clients understand how to process the resource.
|
|
297
|
-
*/
|
|
298
|
-
mimeType?: string;
|
|
299
|
-
/**
|
|
300
|
-
* Human-readable resource name.
|
|
301
|
-
* Displayed to users in resource listings.
|
|
302
|
-
*/
|
|
303
|
-
name: string;
|
|
304
|
-
/**
|
|
305
|
-
* Unique resource URI.
|
|
306
|
-
* Must be a valid URI (file://, https://, custom://, etc.).
|
|
307
|
-
*/
|
|
308
|
-
uri: string;
|
|
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
|
-
/** Optional completion handlers keyed by parameter name. */
|
|
338
|
-
complete?: Record<string, CompletionHandler>;
|
|
339
|
-
/** Optional description. */
|
|
340
|
-
description?: string;
|
|
341
|
-
/** Handler for reading matched resources. */
|
|
342
|
-
handler: ResourceTemplateReadHandler;
|
|
343
|
-
/** Optional MIME type. */
|
|
344
|
-
mimeType?: string;
|
|
345
|
-
/** Human-readable name for the template. */
|
|
346
|
-
name: string;
|
|
347
|
-
/** URI template with `{param}` placeholders (RFC 6570 Level 1). */
|
|
348
|
-
uriTemplate: string;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Result of a completion request.
|
|
352
|
-
*/
|
|
353
|
-
interface CompletionResult {
|
|
354
|
-
/** Whether there are more values */
|
|
355
|
-
hasMore?: boolean;
|
|
356
|
-
/** Total number of available values (for pagination) */
|
|
357
|
-
total?: number;
|
|
358
|
-
/** Completion values */
|
|
359
|
-
values: string[];
|
|
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
|
-
/** Optional completion handler for this argument */
|
|
380
|
-
complete?: CompletionHandler;
|
|
381
|
-
/** Human-readable description */
|
|
382
|
-
description?: string;
|
|
383
|
-
/** Argument name */
|
|
384
|
-
name: string;
|
|
385
|
-
/** Whether this argument is required */
|
|
386
|
-
required?: boolean;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Content block within a prompt message.
|
|
390
|
-
*/
|
|
391
|
-
interface PromptMessageContent {
|
|
392
|
-
/** Optional content annotations */
|
|
393
|
-
annotations?: ContentAnnotations;
|
|
394
|
-
/** Text content */
|
|
395
|
-
text: string;
|
|
396
|
-
/** Content type */
|
|
397
|
-
type: "text";
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* A message in a prompt response.
|
|
401
|
-
*/
|
|
402
|
-
interface PromptMessage {
|
|
403
|
-
/** Message content */
|
|
404
|
-
content: PromptMessageContent;
|
|
405
|
-
/** Message role */
|
|
406
|
-
role: "user" | "assistant";
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Result returned from getting a prompt.
|
|
410
|
-
*/
|
|
411
|
-
interface PromptResult {
|
|
412
|
-
/** Optional description override */
|
|
413
|
-
description?: string;
|
|
414
|
-
/** Prompt messages */
|
|
415
|
-
messages: PromptMessage[];
|
|
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
|
-
/** Prompt arguments */
|
|
442
|
-
arguments: PromptArgument[];
|
|
443
|
-
/** Human-readable description */
|
|
444
|
-
description?: string;
|
|
445
|
-
/** Handler to generate messages */
|
|
446
|
-
handler: PromptHandler;
|
|
447
|
-
/** Unique prompt name */
|
|
448
|
-
name: string;
|
|
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
|
-
/** Progress token from client for tracking progress */
|
|
487
|
-
progressToken?: string | number;
|
|
488
|
-
/** Custom request ID (auto-generated if not provided) */
|
|
489
|
-
requestId?: string;
|
|
490
|
-
/** Abort signal for cancellation */
|
|
491
|
-
signal?: AbortSignal;
|
|
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
|
-
/**
|
|
514
|
-
* Bind the SDK server instance for notifications.
|
|
515
|
-
* Called internally by the transport layer.
|
|
516
|
-
* @param sdkServer - The MCP SDK Server instance
|
|
517
|
-
*/
|
|
518
|
-
bindSdkServer?(sdkServer: any): void;
|
|
519
|
-
/**
|
|
520
|
-
* Complete an argument value.
|
|
521
|
-
* @param ref - Reference to the prompt or resource template
|
|
522
|
-
* @param argumentName - Name of the argument to complete
|
|
523
|
-
* @param value - Current value to complete
|
|
524
|
-
* @returns Result with completion values or McpError
|
|
525
|
-
*/
|
|
526
|
-
complete(ref: CompletionRef, argumentName: string, value: string): Promise<Result<CompletionResult, InstanceType<typeof McpError>>>;
|
|
527
|
-
/**
|
|
528
|
-
* Get a specific prompt's messages.
|
|
529
|
-
* @param name - Prompt name
|
|
530
|
-
* @param args - Prompt arguments
|
|
531
|
-
* @returns Result with prompt result or McpError
|
|
532
|
-
*/
|
|
533
|
-
getPrompt(name: string, args: Record<string, string | undefined>): Promise<Result<PromptResult, InstanceType<typeof McpError>>>;
|
|
534
|
-
/**
|
|
535
|
-
* Get all registered prompts.
|
|
536
|
-
* @returns Array of prompt definitions (without handlers)
|
|
537
|
-
*/
|
|
538
|
-
getPrompts(): Array<{
|
|
539
|
-
name: string;
|
|
540
|
-
description?: string;
|
|
541
|
-
arguments: PromptArgument[];
|
|
542
|
-
}>;
|
|
543
|
-
/**
|
|
544
|
-
* Get all registered resources.
|
|
545
|
-
* @returns Array of resource definitions
|
|
546
|
-
*/
|
|
547
|
-
getResources(): ResourceDefinition[];
|
|
548
|
-
/**
|
|
549
|
-
* Get all registered resource templates.
|
|
550
|
-
* @returns Array of resource template definitions
|
|
551
|
-
*/
|
|
552
|
-
getResourceTemplates(): ResourceTemplateDefinition[];
|
|
553
|
-
/**
|
|
554
|
-
* Get all registered tools.
|
|
555
|
-
* @returns Array of serialized tool information
|
|
556
|
-
*/
|
|
557
|
-
getTools(): SerializedTool[];
|
|
558
|
-
/**
|
|
559
|
-
* Invoke a tool by name.
|
|
560
|
-
* @param name - Tool name
|
|
561
|
-
* @param input - Tool input (will be validated)
|
|
562
|
-
* @param options - Optional invocation options
|
|
563
|
-
* @returns Result with tool output or McpError
|
|
564
|
-
*/
|
|
565
|
-
invokeTool<T = unknown>(name: string, input: unknown, options?: InvokeToolOptions): Promise<Result<T, InstanceType<typeof McpError>>>;
|
|
566
|
-
/** Server name */
|
|
567
|
-
readonly name: string;
|
|
568
|
-
/**
|
|
569
|
-
* Notify connected clients that the prompt list has changed.
|
|
570
|
-
*/
|
|
571
|
-
notifyPromptsChanged(): void;
|
|
572
|
-
/**
|
|
573
|
-
* Notify connected clients that the resource list has changed.
|
|
574
|
-
*/
|
|
575
|
-
notifyResourcesChanged(): void;
|
|
576
|
-
/**
|
|
577
|
-
* Notify connected clients that a specific resource has been updated.
|
|
578
|
-
* Only emits for subscribed URIs.
|
|
579
|
-
* @param uri - URI of the updated resource
|
|
580
|
-
*/
|
|
581
|
-
notifyResourceUpdated(uri: string): void;
|
|
582
|
-
/**
|
|
583
|
-
* Notify connected clients that the tool list has changed.
|
|
584
|
-
*/
|
|
585
|
-
notifyToolsChanged(): void;
|
|
586
|
-
/**
|
|
587
|
-
* Read a resource by URI.
|
|
588
|
-
* @param uri - Resource URI
|
|
589
|
-
* @returns Result with resource content or McpError
|
|
590
|
-
*/
|
|
591
|
-
readResource(uri: string): Promise<Result<ResourceContent[], InstanceType<typeof McpError>>>;
|
|
592
|
-
/**
|
|
593
|
-
* Register a prompt with the server.
|
|
594
|
-
* @param prompt - Prompt definition to register
|
|
595
|
-
*/
|
|
596
|
-
registerPrompt(prompt: PromptDefinition): void;
|
|
597
|
-
/**
|
|
598
|
-
* Register a resource with the server.
|
|
599
|
-
* @param resource - Resource definition to register
|
|
600
|
-
*/
|
|
601
|
-
registerResource(resource: ResourceDefinition): void;
|
|
602
|
-
/**
|
|
603
|
-
* Register a resource template with the server.
|
|
604
|
-
* @param template - Resource template definition to register
|
|
605
|
-
*/
|
|
606
|
-
registerResourceTemplate(template: ResourceTemplateDefinition): void;
|
|
607
|
-
/**
|
|
608
|
-
* Register a tool with the server.
|
|
609
|
-
* @param tool - Tool definition to register
|
|
610
|
-
*/
|
|
611
|
-
registerTool<
|
|
612
|
-
TInput,
|
|
613
|
-
TOutput,
|
|
614
|
-
TError extends OutfitterError
|
|
615
|
-
>(tool: ToolDefinition<TInput, TOutput, TError>): void;
|
|
616
|
-
/**
|
|
617
|
-
* Send a log message to connected clients.
|
|
618
|
-
* Filters by the client-requested log level threshold.
|
|
619
|
-
* No-op if no SDK server is bound or if the message is below the threshold.
|
|
620
|
-
*
|
|
621
|
-
* @param level - MCP log level for the message
|
|
622
|
-
* @param data - Log data (string, object, or any serializable value)
|
|
623
|
-
* @param loggerName - Optional logger name for client-side filtering
|
|
624
|
-
*/
|
|
625
|
-
sendLogMessage(level: McpLogLevel, data: unknown, loggerName?: string): void;
|
|
626
|
-
/**
|
|
627
|
-
* Set the client-requested log level.
|
|
628
|
-
* Only log messages at or above this level will be forwarded.
|
|
629
|
-
* @param level - MCP log level string
|
|
630
|
-
*/
|
|
631
|
-
setLogLevel?(level: string): void;
|
|
632
|
-
/**
|
|
633
|
-
* Start the MCP server.
|
|
634
|
-
* Begins listening for client connections.
|
|
635
|
-
*/
|
|
636
|
-
start(): Promise<void>;
|
|
637
|
-
/**
|
|
638
|
-
* Stop the MCP server.
|
|
639
|
-
* Closes all connections and cleans up resources.
|
|
640
|
-
*/
|
|
641
|
-
stop(): Promise<void>;
|
|
642
|
-
/**
|
|
643
|
-
* Subscribe to updates for a resource URI.
|
|
644
|
-
* @param uri - Resource URI to subscribe to
|
|
645
|
-
*/
|
|
646
|
-
subscribe(uri: string): void;
|
|
647
|
-
/**
|
|
648
|
-
* Unsubscribe from updates for a resource URI.
|
|
649
|
-
* @param uri - Resource URI to unsubscribe from
|
|
650
|
-
*/
|
|
651
|
-
unsubscribe(uri: string): void;
|
|
652
|
-
/** Server version */
|
|
653
|
-
readonly version: string;
|
|
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
|
-
/** Progress reporter, present when client provides a progressToken */
|
|
673
|
-
progress?: ProgressReporter;
|
|
674
|
-
/** The name of the tool being invoked */
|
|
675
|
-
toolName?: string;
|
|
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 };
|