@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
@@ -1,165 +0,0 @@
1
- // @bun
2
- // packages/mcp/src/transport.ts
3
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
- import {
6
- CallToolRequestSchema,
7
- CompleteRequestSchema,
8
- GetPromptRequestSchema,
9
- ListPromptsRequestSchema,
10
- ListResourcesRequestSchema,
11
- ListResourceTemplatesRequestSchema,
12
- ListToolsRequestSchema,
13
- ReadResourceRequestSchema,
14
- McpError as SdkMcpError,
15
- SetLevelRequestSchema,
16
- SubscribeRequestSchema,
17
- UnsubscribeRequestSchema
18
- } from "@modelcontextprotocol/sdk/types.js";
19
- import { safeStringify } from "@outfitter/contracts";
20
- function isMcpToolResponse(value) {
21
- if (!value || typeof value !== "object") {
22
- return false;
23
- }
24
- const content = value.content;
25
- return Array.isArray(content);
26
- }
27
- function toTextPayload(value) {
28
- if (typeof value === "string") {
29
- return value;
30
- }
31
- return safeStringify(value);
32
- }
33
- function serializeError(error) {
34
- if (error && typeof error === "object") {
35
- const record = error;
36
- return {
37
- _tag: record._tag ?? "McpError",
38
- message: record.message ?? "Unknown error",
39
- code: record.code,
40
- context: record.context
41
- };
42
- }
43
- return {
44
- _tag: "McpError",
45
- message: String(error)
46
- };
47
- }
48
- function wrapToolResult(value) {
49
- if (isMcpToolResponse(value)) {
50
- return value;
51
- }
52
- const structuredContent = value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
53
- return {
54
- content: [
55
- {
56
- type: "text",
57
- text: toTextPayload(value)
58
- }
59
- ],
60
- ...structuredContent ? { structuredContent } : {}
61
- };
62
- }
63
- function wrapToolError(error) {
64
- return {
65
- content: [
66
- {
67
- type: "text",
68
- text: toTextPayload(serializeError(error))
69
- }
70
- ],
71
- isError: true
72
- };
73
- }
74
- function toSdkError(error) {
75
- return new SdkMcpError(error.code, error.message, error.context);
76
- }
77
- function createSdkServer(server) {
78
- const capabilities = {
79
- tools: { listChanged: true },
80
- resources: { listChanged: true, subscribe: true },
81
- prompts: { listChanged: true },
82
- completions: {},
83
- logging: {}
84
- };
85
- const sdkServer = new Server({ name: server.name, version: server.version }, { capabilities });
86
- sdkServer.setRequestHandler(ListToolsRequestSchema, async () => ({
87
- tools: server.getTools()
88
- }));
89
- sdkServer.setRequestHandler(CallToolRequestSchema, async (request) => {
90
- const { name, arguments: args } = request.params;
91
- const progressToken = request.params._meta?.progressToken;
92
- const options = progressToken !== undefined ? { progressToken } : undefined;
93
- const result = await server.invokeTool(name, args ?? {}, options);
94
- if (result.isErr()) {
95
- return wrapToolError(result.error);
96
- }
97
- return wrapToolResult(result.value);
98
- });
99
- sdkServer.setRequestHandler(ListResourcesRequestSchema, async () => ({
100
- resources: server.getResources().map((r) => ({
101
- uri: r.uri,
102
- name: r.name,
103
- ...r.description ? { description: r.description } : {},
104
- ...r.mimeType ? { mimeType: r.mimeType } : {}
105
- }))
106
- }));
107
- sdkServer.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({
108
- resourceTemplates: server.getResourceTemplates().map((t) => ({
109
- uriTemplate: t.uriTemplate,
110
- name: t.name,
111
- ...t.description ? { description: t.description } : {},
112
- ...t.mimeType ? { mimeType: t.mimeType } : {}
113
- }))
114
- }));
115
- sdkServer.setRequestHandler(ReadResourceRequestSchema, async (request) => {
116
- const { uri } = request.params;
117
- const result = await server.readResource(uri);
118
- if (result.isErr()) {
119
- throw toSdkError(result.error);
120
- }
121
- return { contents: result.value };
122
- });
123
- sdkServer.setRequestHandler(SubscribeRequestSchema, async (request) => {
124
- server.subscribe(request.params.uri);
125
- return {};
126
- });
127
- sdkServer.setRequestHandler(UnsubscribeRequestSchema, async (request) => {
128
- server.unsubscribe(request.params.uri);
129
- return {};
130
- });
131
- sdkServer.setRequestHandler(ListPromptsRequestSchema, async () => ({
132
- prompts: server.getPrompts()
133
- }));
134
- sdkServer.setRequestHandler(GetPromptRequestSchema, async (request) => {
135
- const { name, arguments: args } = request.params;
136
- const result = await server.getPrompt(name, args ?? {});
137
- if (result.isErr()) {
138
- throw toSdkError(result.error);
139
- }
140
- return { ...result.value };
141
- });
142
- sdkServer.setRequestHandler(CompleteRequestSchema, async (request) => {
143
- const { ref, argument } = request.params;
144
- const completionRef = ref.type === "ref/prompt" ? { type: "ref/prompt", name: ref.name } : { type: "ref/resource", uri: ref.uri };
145
- const result = await server.complete(completionRef, argument.name, argument.value);
146
- if (result.isErr()) {
147
- throw toSdkError(result.error);
148
- }
149
- return { completion: result.value };
150
- });
151
- sdkServer.setRequestHandler(SetLevelRequestSchema, async (request) => {
152
- const level = request.params.level;
153
- server.setLogLevel?.(level);
154
- return {};
155
- });
156
- server.bindSdkServer?.(sdkServer);
157
- return sdkServer;
158
- }
159
- async function connectStdio(server, transport = new StdioServerTransport) {
160
- const sdkServer = createSdkServer(server);
161
- await sdkServer.connect(transport);
162
- return sdkServer;
163
- }
164
-
165
- export { wrapToolResult, wrapToolError, createSdkServer, connectStdio };
@@ -1,28 +0,0 @@
1
- // @bun
2
- import {
3
- defineTool
4
- } from "./mcp-hh12tqfg.js";
5
-
6
- // packages/mcp/src/actions.ts
7
- import { DEFAULT_REGISTRY_SURFACES } from "@outfitter/contracts";
8
- function isActionRegistry(source) {
9
- return "list" in source;
10
- }
11
- function buildMcpTools(source, options = {}) {
12
- const actions = isActionRegistry(source) ? source.list() : source;
13
- const includeSurfaces = options.includeSurfaces ?? [
14
- "mcp"
15
- ];
16
- return actions.filter((action) => {
17
- const surfaces = action.surfaces ?? DEFAULT_REGISTRY_SURFACES;
18
- return surfaces.some((surface) => includeSurfaces.includes(surface));
19
- }).map((action) => defineTool({
20
- name: action.mcp?.tool ?? action.id,
21
- description: action.mcp?.description ?? action.description ?? action.id,
22
- inputSchema: action.input,
23
- handler: async (input, ctx) => action.handler(input, ctx),
24
- ...action.mcp?.deferLoading !== undefined ? { deferLoading: action.mcp.deferLoading } : {}
25
- }));
26
- }
27
-
28
- export { buildMcpTools };
@@ -1,143 +0,0 @@
1
- // @bun
2
- // packages/mcp/src/core-tools.ts
3
- import { Result, ValidationError } from "@outfitter/contracts";
4
- import { z } from "zod";
5
- var DEFAULT_DOCS = {
6
- overview: "No documentation configured yet.",
7
- tools: [],
8
- examples: [],
9
- schemas: {}
10
- };
11
- var docsSchema = z.object({
12
- section: z.enum(["overview", "tools", "examples", "schemas"]).optional()
13
- });
14
- function pickDocsSection(payload, section) {
15
- if (!section) {
16
- return payload;
17
- }
18
- return {
19
- [section]: payload[section]
20
- };
21
- }
22
- function defineDocsTool(options = {}) {
23
- return {
24
- name: "docs",
25
- description: options.description ?? "Documentation, usage patterns, and examples for this MCP server.",
26
- deferLoading: false,
27
- inputSchema: docsSchema,
28
- handler: async (input) => {
29
- const payload = options.getDocs ? await options.getDocs(input.section) : options.docs ?? DEFAULT_DOCS;
30
- return Result.ok(pickDocsSection(payload, input.section));
31
- }
32
- };
33
- }
34
- var configSchema = z.object({
35
- action: z.enum(["get", "set", "list"]),
36
- key: z.string().optional(),
37
- value: z.unknown().optional()
38
- });
39
- function createInMemoryStore(initial = {}) {
40
- const store = new Map(Object.entries(initial));
41
- return {
42
- get(key) {
43
- return { value: store.get(key), found: store.has(key) };
44
- },
45
- set(key, value) {
46
- store.set(key, value);
47
- },
48
- list() {
49
- return Object.fromEntries(store.entries());
50
- }
51
- };
52
- }
53
- function defineConfigTool(options = {}) {
54
- const store = options.store ?? createInMemoryStore(options.initial);
55
- return {
56
- name: "config",
57
- description: options.description ?? "Read or modify server configuration values.",
58
- deferLoading: false,
59
- inputSchema: configSchema,
60
- handler: async (input) => {
61
- switch (input.action) {
62
- case "list": {
63
- const config = await store.list();
64
- return Result.ok({ action: "list", config });
65
- }
66
- case "get": {
67
- if (!input.key) {
68
- return Result.err(new ValidationError({
69
- message: "Config key is required for action 'get'.",
70
- field: "key"
71
- }));
72
- }
73
- const { value, found } = await store.get(input.key);
74
- return Result.ok({ action: "get", key: input.key, value, found });
75
- }
76
- case "set": {
77
- if (!input.key) {
78
- return Result.err(new ValidationError({
79
- message: "Config key is required for action 'set'.",
80
- field: "key"
81
- }));
82
- }
83
- await store.set(input.key, input.value);
84
- return Result.ok({
85
- action: "set",
86
- key: input.key,
87
- value: input.value
88
- });
89
- }
90
- default:
91
- return Result.err(new ValidationError({
92
- message: `Unknown action: ${input.action}`,
93
- field: "action"
94
- }));
95
- }
96
- }
97
- };
98
- }
99
- var querySchema = z.object({
100
- q: z.string().min(1).describe("Search query. Supports natural language or filter syntax.").optional(),
101
- query: z.string().min(1).describe("Alias for q. Supports natural language or filter syntax.").optional(),
102
- limit: z.number().int().positive().optional(),
103
- cursor: z.string().optional(),
104
- filters: z.record(z.string(), z.unknown()).optional()
105
- }).refine((value) => {
106
- const queryValue = (value.q ?? value.query)?.trim();
107
- return typeof queryValue === "string" && queryValue.length > 0;
108
- }, {
109
- message: "Query is required.",
110
- path: ["q"]
111
- });
112
- function defineQueryTool(options = {}) {
113
- return {
114
- name: "query",
115
- description: options.description ?? "Search and discover resources with filters and pagination.",
116
- deferLoading: false,
117
- inputSchema: querySchema,
118
- handler: (input, ctx) => {
119
- const normalized = {
120
- ...input,
121
- q: (input.q ?? input.query ?? "").trim()
122
- };
123
- if (options.handler) {
124
- return options.handler(normalized, ctx);
125
- }
126
- return Promise.resolve(Result.ok({
127
- results: [],
128
- _meta: {
129
- note: "No query handler configured."
130
- }
131
- }));
132
- }
133
- };
134
- }
135
- function createCoreTools(options = {}) {
136
- return [
137
- defineDocsTool(options.docs),
138
- defineConfigTool(options.config),
139
- defineQueryTool(options.query)
140
- ];
141
- }
142
-
143
- export { defineDocsTool, defineConfigTool, defineQueryTool, createCoreTools };
@@ -1,5 +0,0 @@
1
- // @bun
2
- // packages/mcp/src/schema.ts
3
- import { zodToJsonSchema } from "@outfitter/contracts/schema";
4
-
5
- export { zodToJsonSchema };