@open-wa/mcp 5.0.0-alpha.8 → 5.0.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/LICENSE.md +2 -2
- package/README.md +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -169
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +15 -169
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -12
- package/.turbo/turbo-build.log +0 -26
- package/CHANGELOG.md +0 -88
- package/src/adapter/hono-mcp.ts +0 -207
- package/src/execution/args.ts +0 -59
- package/src/execution/errors.ts +0 -56
- package/src/execution/invoke.ts +0 -32
- package/src/execution/kernel.ts +0 -104
- package/src/index.ts +0 -7
- package/src/manifest.ts +0 -91
- package/src/tool-naming.ts +0 -11
- package/test/adapter.test.ts +0 -181
- package/test/kernel.test.ts +0 -151
- package/test/manifest.test.ts +0 -61
- package/tsdown.config.ts +0 -12
- package/vitest.config.ts +0 -10
package/src/adapter/hono-mcp.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
-
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
3
|
-
import {
|
|
4
|
-
CallToolRequestSchema,
|
|
5
|
-
ListToolsRequestSchema,
|
|
6
|
-
} from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import type { Hono, Context } from 'hono';
|
|
8
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
9
|
-
import type { Config } from '@open-wa/schema';
|
|
10
|
-
import { getMcpToolDefinitions } from '../manifest';
|
|
11
|
-
import { executeCapability } from '../execution/kernel';
|
|
12
|
-
|
|
13
|
-
export interface HonoMcpAdapterOptions {
|
|
14
|
-
config: Config;
|
|
15
|
-
/**
|
|
16
|
-
* Getter for the active client instance.
|
|
17
|
-
*/
|
|
18
|
-
clientSource: () => Record<string, any> | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Optional logging emitter.
|
|
21
|
-
*/
|
|
22
|
-
elasticEmitter?: {
|
|
23
|
-
log: (data: any) => void;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Base path for tool documentation links.
|
|
27
|
-
*/
|
|
28
|
-
basePath?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Getter for session readiness state.
|
|
31
|
-
* Used for lifecycle gating parity with HTTP transport.
|
|
32
|
-
*/
|
|
33
|
-
isSessionConnected?: () => boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Creates an MCP adapter using the Streamable HTTP transport (single-endpoint).
|
|
38
|
-
*
|
|
39
|
-
* open-wa product decision:
|
|
40
|
-
* hosted MCP is Easy API-only and unavailable through createClient()
|
|
41
|
-
*
|
|
42
|
-
* This adapter:
|
|
43
|
-
* - Uses WebStandardStreamableHTTPServerTransport for a single-endpoint /mcp shape
|
|
44
|
-
* - Enforces Easy API API-key auth on every request
|
|
45
|
-
* - Gates tool execution on session readiness (parity with HTTP transport)
|
|
46
|
-
* - Returns protocol errors for malformed protocol requests
|
|
47
|
-
* - Returns tool-level errors for open-wa execution failures
|
|
48
|
-
*/
|
|
49
|
-
export function createHonoMcpAdapter(options: HonoMcpAdapterOptions) {
|
|
50
|
-
const { config, clientSource, elasticEmitter, basePath = '/api', isSessionConnected } = options;
|
|
51
|
-
const toolDefinitions = getMcpToolDefinitions(basePath);
|
|
52
|
-
const toolMap = new Map(toolDefinitions.map((d) => [d.toolName, d]));
|
|
53
|
-
|
|
54
|
-
const server = new Server(
|
|
55
|
-
{
|
|
56
|
-
name: 'open-wa',
|
|
57
|
-
version: '5.0.0',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
capabilities: {
|
|
61
|
-
tools: {},
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// ── tools/list ──────────────────────────────────────────────────────
|
|
67
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
68
|
-
return {
|
|
69
|
-
tools: toolDefinitions.map((def) => ({
|
|
70
|
-
name: def.toolName,
|
|
71
|
-
description: def.description,
|
|
72
|
-
inputSchema: zodToJsonSchema(def.inputSchema) as any,
|
|
73
|
-
})),
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// ── tools/call ──────────────────────────────────────────────────────
|
|
78
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
79
|
-
const { name, arguments: args } = request.params;
|
|
80
|
-
const definition = toolMap.get(name);
|
|
81
|
-
|
|
82
|
-
if (!definition) {
|
|
83
|
-
return {
|
|
84
|
-
isError: true,
|
|
85
|
-
content: [
|
|
86
|
-
{
|
|
87
|
-
type: 'text' as const,
|
|
88
|
-
text: `Unknown tool: ${name}. Use tools/list to discover available tools.`,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ── Lifecycle/readiness gate (parity with HTTP transport) ──────
|
|
95
|
-
if (isSessionConnected && !isSessionConnected()) {
|
|
96
|
-
if (config.apiLifecycle !== 'immediate') {
|
|
97
|
-
return {
|
|
98
|
-
isError: true,
|
|
99
|
-
content: [
|
|
100
|
-
{
|
|
101
|
-
type: 'text' as const,
|
|
102
|
-
text: 'Session is not connected or ready. Tool execution is blocked until the session is fully ready.',
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const result = await executeCapability({
|
|
110
|
-
client: clientSource(),
|
|
111
|
-
definition: definition as any,
|
|
112
|
-
payload: (args as Record<string, unknown>) || {},
|
|
113
|
-
elasticEmitter,
|
|
114
|
-
sessionId: config.sessionId,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
if (result.success) {
|
|
118
|
-
return {
|
|
119
|
-
content: [
|
|
120
|
-
{
|
|
121
|
-
type: 'text' as const,
|
|
122
|
-
text: JSON.stringify(result.data, null, 2),
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
isError: true,
|
|
130
|
-
content: [
|
|
131
|
-
{
|
|
132
|
-
type: 'text' as const,
|
|
133
|
-
text: result.error || 'Internal Execution Error',
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// ── Streamable HTTP transport ───────────────────────────────────────
|
|
140
|
-
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
141
|
-
sessionIdGenerator: () => crypto.randomUUID(),
|
|
142
|
-
onsessioninitialized: (sessionId: string) => {
|
|
143
|
-
elasticEmitter?.log({
|
|
144
|
-
level: 'info',
|
|
145
|
-
component: 'mcp',
|
|
146
|
-
message: `MCP session initialized: ${sessionId}`,
|
|
147
|
-
sessionId: config.sessionId,
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
onsessionclosed: (sessionId: string) => {
|
|
151
|
-
elasticEmitter?.log({
|
|
152
|
-
level: 'info',
|
|
153
|
-
component: 'mcp',
|
|
154
|
-
message: `MCP session closed: ${sessionId}`,
|
|
155
|
-
sessionId: config.sessionId,
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Connect the server to the transport immediately
|
|
161
|
-
server.connect(transport);
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
/**
|
|
165
|
-
* Mounts the MCP Streamable HTTP endpoint on the provided Hono app.
|
|
166
|
-
*
|
|
167
|
-
* This creates a single endpoint at `path` that handles:
|
|
168
|
-
* - POST: JSON-RPC messages (initialize, tools/list, tools/call)
|
|
169
|
-
* - GET: Server-initiated SSE stream
|
|
170
|
-
* - DELETE: Session termination
|
|
171
|
-
*
|
|
172
|
-
* API-key auth is enforced on every request before delegation to MCP.
|
|
173
|
-
*/
|
|
174
|
-
mount: (app: Hono, path: string) => {
|
|
175
|
-
app.all(`${path}`, async (c: Context) => {
|
|
176
|
-
// ── API-key auth enforcement ───────────────────────────────
|
|
177
|
-
// MCP inherits Easy API auth boundary. No key = no access.
|
|
178
|
-
if (config.apiKey) {
|
|
179
|
-
const headerKey =
|
|
180
|
-
c.req.header('X-API-Key') ||
|
|
181
|
-
c.req.header('api_key') ||
|
|
182
|
-
c.req.header('key');
|
|
183
|
-
const resolvedKey = headerKey;
|
|
184
|
-
|
|
185
|
-
if (!resolvedKey || resolvedKey !== config.apiKey) {
|
|
186
|
-
return c.json(
|
|
187
|
-
{ error: 'Unauthorized', details: 'Invalid or missing API key for MCP endpoint' },
|
|
188
|
-
401,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// ── Delegate to Streamable HTTP transport ──────────────────
|
|
194
|
-
const response = await transport.handleRequest(c.req.raw);
|
|
195
|
-
return response;
|
|
196
|
-
});
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Cleanly shut down the MCP transport.
|
|
201
|
-
*/
|
|
202
|
-
close: async () => {
|
|
203
|
-
await transport.close();
|
|
204
|
-
await server.close();
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
}
|
package/src/execution/args.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { normalizeParameterKeys, z, type HttpMethodDefinition } from '@open-wa/schema';
|
|
2
|
-
|
|
3
|
-
function mapArrayArgs(def: HttpMethodDefinition, args: unknown[]): Record<string, unknown> {
|
|
4
|
-
return def.parameterOrder.reduce<Record<string, unknown>>((acc, key, index) => {
|
|
5
|
-
if (index < args.length) {
|
|
6
|
-
acc[key] = args[index];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Normalizes an input payload into a form suitable for schema validation.
|
|
15
|
-
* Handles:
|
|
16
|
-
* 1. Array-based positional arguments
|
|
17
|
-
* 2. Mixed key aliases (legacy vs canonical)
|
|
18
|
-
* 3. Wrapped 'args' or 'input' properties
|
|
19
|
-
*/
|
|
20
|
-
export function normalizeMethodPayload(def: HttpMethodDefinition, payload: unknown): any {
|
|
21
|
-
if (Array.isArray(payload)) {
|
|
22
|
-
return normalizeParameterKeys(mapArrayArgs(def, payload), def.keyAliasMap);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!payload || typeof payload !== 'object') {
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const record = payload as Record<string, unknown>;
|
|
30
|
-
|
|
31
|
-
if ('args' in record) {
|
|
32
|
-
const args = record.args;
|
|
33
|
-
|
|
34
|
-
if (Array.isArray(args)) {
|
|
35
|
-
return normalizeParameterKeys(mapArrayArgs(def, args), def.keyAliasMap);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (args && typeof args === 'object') {
|
|
39
|
-
return normalizeParameterKeys(args as Record<string, any>, def.keyAliasMap);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (record.input && typeof record.input === 'object' && !Array.isArray(record.input)) {
|
|
44
|
-
return normalizeParameterKeys(record.input as Record<string, any>, def.keyAliasMap);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (def.inputSchema instanceof z.ZodObject) {
|
|
48
|
-
const knownKeys = new Set(Object.keys(def.inputSchema.shape));
|
|
49
|
-
const filtered = Object.fromEntries(
|
|
50
|
-
Object.entries(record).filter(([key]) => knownKeys.has(key))
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
if (Object.keys(filtered).length > 0) {
|
|
54
|
-
return normalizeParameterKeys(filtered, def.keyAliasMap);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return normalizeParameterKeys(record, def.keyAliasMap);
|
|
59
|
-
}
|
package/src/execution/errors.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP execution error types.
|
|
3
|
-
*
|
|
4
|
-
* Maintains the separation between protocol-level errors
|
|
5
|
-
* (JSON-RPC envelope issues) and tool-level errors
|
|
6
|
-
* (open-wa runtime invocation failures).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A tool execution error from the open-wa runtime.
|
|
11
|
-
* This should be surfaced as `isError: true` in MCP tool results,
|
|
12
|
-
* NOT as a JSON-RPC protocol error.
|
|
13
|
-
*/
|
|
14
|
-
export class ToolExecutionError extends Error {
|
|
15
|
-
public readonly statusCode: number;
|
|
16
|
-
public readonly details?: unknown;
|
|
17
|
-
|
|
18
|
-
constructor(message: string, statusCode = 500, details?: unknown) {
|
|
19
|
-
super(message);
|
|
20
|
-
this.name = 'ToolExecutionError';
|
|
21
|
-
this.statusCode = statusCode;
|
|
22
|
-
this.details = details;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A validation error from Zod schema parsing.
|
|
28
|
-
* This should be surfaced as `isError: true` in MCP tool results
|
|
29
|
-
* with the validation details attached.
|
|
30
|
-
*/
|
|
31
|
-
export class ToolValidationError extends ToolExecutionError {
|
|
32
|
-
constructor(message: string, details?: unknown) {
|
|
33
|
-
super(message, 400, details);
|
|
34
|
-
this.name = 'ToolValidationError';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Thrown when the client/session is not ready for execution.
|
|
40
|
-
*/
|
|
41
|
-
export class SessionNotReadyError extends ToolExecutionError {
|
|
42
|
-
constructor(message = 'Session is not connected or ready for execution') {
|
|
43
|
-
super(message, 503);
|
|
44
|
-
this.name = 'SessionNotReadyError';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Thrown when authentication is missing or invalid.
|
|
50
|
-
*/
|
|
51
|
-
export class AuthenticationError extends ToolExecutionError {
|
|
52
|
-
constructor(message = 'Authentication required. Provide a valid API key.') {
|
|
53
|
-
super(message, 401);
|
|
54
|
-
this.name = 'AuthenticationError';
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/execution/invoke.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export interface ClientMethodDefinitionLike {
|
|
2
|
-
functionName: string;
|
|
3
|
-
parameterOrder: string[];
|
|
4
|
-
wapiOverride?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Invokes a client method by resolving its implementation from the client instance
|
|
9
|
-
* and mapping the payload to positional arguments if necessary.
|
|
10
|
-
*/
|
|
11
|
-
export async function invokeClientMethod(
|
|
12
|
-
client: Record<string, (...args: any[]) => Promise<any> | any> | undefined,
|
|
13
|
-
def: ClientMethodDefinitionLike,
|
|
14
|
-
payload: unknown
|
|
15
|
-
): Promise<any> {
|
|
16
|
-
if (!client) {
|
|
17
|
-
throw new Error('Client not initialized');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const method = client[def.functionName] ?? (def.wapiOverride ? client[def.wapiOverride] : undefined);
|
|
21
|
-
|
|
22
|
-
if (typeof method !== 'function') {
|
|
23
|
-
throw new Error(`Method ${def.functionName} not implemented on Client`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
27
|
-
return await method.call(client);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const resolvedArgs = def.parameterOrder.map((key) => (payload as Record<string, unknown>)[key]);
|
|
31
|
-
return await method.call(client, ...resolvedArgs);
|
|
32
|
-
}
|
package/src/execution/kernel.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { HttpMethodDefinition } from '@open-wa/schema';
|
|
2
|
-
import { normalizeMethodPayload } from './args';
|
|
3
|
-
import { invokeClientMethod } from './invoke';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Context required to execute an Open-WA capability via any transport.
|
|
7
|
-
*/
|
|
8
|
-
export interface ExecutionContext {
|
|
9
|
-
/**
|
|
10
|
-
* The active client instance or proxy.
|
|
11
|
-
*/
|
|
12
|
-
client: Record<string, (...args: any[]) => Promise<any> | any> | undefined;
|
|
13
|
-
/**
|
|
14
|
-
* The metadata definition for the method being invoked.
|
|
15
|
-
*/
|
|
16
|
-
definition: HttpMethodDefinition;
|
|
17
|
-
/**
|
|
18
|
-
* The raw input payload (merged query + body, or MCP arguments).
|
|
19
|
-
*/
|
|
20
|
-
payload: Record<string, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Optional diagnostic emitter for logging.
|
|
23
|
-
*/
|
|
24
|
-
elasticEmitter?: {
|
|
25
|
-
log: (data: any) => void;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* The unique session identifier.
|
|
29
|
-
*/
|
|
30
|
-
sessionId: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Standardized result of a capability execution.
|
|
35
|
-
*/
|
|
36
|
-
export interface ExecutionResult<T = any> {
|
|
37
|
-
success: boolean;
|
|
38
|
-
data?: T;
|
|
39
|
-
error?: string;
|
|
40
|
-
details?: any;
|
|
41
|
-
status: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The shared execution kernel for Open-WA capabilities.
|
|
46
|
-
* Ensures strict parity between HTTP API and MCP transport by centralizing
|
|
47
|
-
* normalization, validation, and invocation logic.
|
|
48
|
-
*/
|
|
49
|
-
export async function executeCapability(
|
|
50
|
-
ctx: ExecutionContext
|
|
51
|
-
): Promise<ExecutionResult> {
|
|
52
|
-
const { client, definition, payload, elasticEmitter, sessionId } = ctx;
|
|
53
|
-
const startTime = Date.now();
|
|
54
|
-
const methodName = definition.functionName;
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
// 1. Normalize aliases and legacy keys
|
|
58
|
-
const normalizedPayload = normalizeMethodPayload(definition, payload);
|
|
59
|
-
|
|
60
|
-
// 2. Validate against Zod schema (strict)
|
|
61
|
-
const validated = await definition.inputSchema.parseAsync(normalizedPayload);
|
|
62
|
-
|
|
63
|
-
// 3. Invoke the client method with positional argument resolution
|
|
64
|
-
const result = await invokeClientMethod(client, definition, validated);
|
|
65
|
-
|
|
66
|
-
// 4. Log successful execution to monitoring if available
|
|
67
|
-
elasticEmitter?.log({
|
|
68
|
-
level: 'info',
|
|
69
|
-
component: 'api',
|
|
70
|
-
method: methodName,
|
|
71
|
-
sessionId,
|
|
72
|
-
duration: Date.now() - startTime,
|
|
73
|
-
statusCode: 200,
|
|
74
|
-
message: `Successfully executed ${methodName}`,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
success: true,
|
|
79
|
-
data: result,
|
|
80
|
-
status: 200,
|
|
81
|
-
};
|
|
82
|
-
} catch (error: any) {
|
|
83
|
-
const isValidationError = error?.name === 'ZodError';
|
|
84
|
-
const status = isValidationError ? 400 : 500;
|
|
85
|
-
|
|
86
|
-
// Log failure to monitoring
|
|
87
|
-
elasticEmitter?.log({
|
|
88
|
-
level: 'error',
|
|
89
|
-
component: 'api',
|
|
90
|
-
method: methodName,
|
|
91
|
-
sessionId,
|
|
92
|
-
duration: Date.now() - startTime,
|
|
93
|
-
statusCode: status,
|
|
94
|
-
message: error?.message || 'Internal Server Error',
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
error: isValidationError ? 'Validation Error' : (error?.message || 'Internal Server Error'),
|
|
100
|
-
details: isValidationError ? error.issues : undefined,
|
|
101
|
-
status,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
package/src/index.ts
DELETED
package/src/manifest.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { getHttpMethodDefinitions, type HttpMethodDefinition } from '@open-wa/schema/http-manifest';
|
|
2
|
-
import { getCanonicalToolName } from './tool-naming';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* MCP-specific projection of a method capability.
|
|
6
|
-
*/
|
|
7
|
-
export interface McpToolDefinition {
|
|
8
|
-
/**
|
|
9
|
-
* The canonical namespaced tool name for MCP.
|
|
10
|
-
* @example 'messages.sendText'
|
|
11
|
-
*/
|
|
12
|
-
toolName: string;
|
|
13
|
-
/**
|
|
14
|
-
* The raw function name in the client.
|
|
15
|
-
* @example 'sendText'
|
|
16
|
-
*/
|
|
17
|
-
functionName: string;
|
|
18
|
-
/**
|
|
19
|
-
* The namespaced name (method part only).
|
|
20
|
-
* @example 'sendText'
|
|
21
|
-
*/
|
|
22
|
-
namespacedName: string;
|
|
23
|
-
/**
|
|
24
|
-
* The namespace this method belongs to.
|
|
25
|
-
* @example 'messages'
|
|
26
|
-
*/
|
|
27
|
-
namespace: string;
|
|
28
|
-
/**
|
|
29
|
-
* Human-readable description of the tool.
|
|
30
|
-
*/
|
|
31
|
-
description: string;
|
|
32
|
-
/**
|
|
33
|
-
* Zod input schema.
|
|
34
|
-
*/
|
|
35
|
-
inputSchema: HttpMethodDefinition['inputSchema'];
|
|
36
|
-
/**
|
|
37
|
-
* Zod output schema.
|
|
38
|
-
*/
|
|
39
|
-
outputSchema: HttpMethodDefinition['outputSchema'];
|
|
40
|
-
/**
|
|
41
|
-
* Preserved parameter order for positional resolution.
|
|
42
|
-
*/
|
|
43
|
-
parameterOrder: string[];
|
|
44
|
-
/**
|
|
45
|
-
* Known aliases for this method.
|
|
46
|
-
*/
|
|
47
|
-
aliases: string[];
|
|
48
|
-
/**
|
|
49
|
-
* Deprecated aliases for this method.
|
|
50
|
-
*/
|
|
51
|
-
deprecatedAliases: string[];
|
|
52
|
-
/**
|
|
53
|
-
* Map of payload key aliases to canonical keys.
|
|
54
|
-
*/
|
|
55
|
-
keyAliasMap: Record<string, string>;
|
|
56
|
-
/**
|
|
57
|
-
* Optional metadata hints for AI clients.
|
|
58
|
-
*/
|
|
59
|
-
annotations?: {
|
|
60
|
-
title?: string;
|
|
61
|
-
readOnlyHint?: boolean;
|
|
62
|
-
destructiveHint?: boolean;
|
|
63
|
-
idempotentHint?: boolean;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Projects the schema registry into a list of canonical MCP tool definitions.
|
|
69
|
-
*/
|
|
70
|
-
export function getMcpToolDefinitions(basePath = '/api'): McpToolDefinition[] {
|
|
71
|
-
return getHttpMethodDefinitions(basePath).map((def) => {
|
|
72
|
-
return {
|
|
73
|
-
toolName: getCanonicalToolName(def.namespace, def.namespacedName),
|
|
74
|
-
functionName: def.functionName,
|
|
75
|
-
namespacedName: def.namespacedName,
|
|
76
|
-
namespace: def.namespace,
|
|
77
|
-
description: def.description,
|
|
78
|
-
inputSchema: def.inputSchema,
|
|
79
|
-
outputSchema: def.outputSchema,
|
|
80
|
-
parameterOrder: def.parameterOrder,
|
|
81
|
-
aliases: def.aliases,
|
|
82
|
-
deprecatedAliases: def.deprecatedAliases,
|
|
83
|
-
keyAliasMap: def.keyAliasMap,
|
|
84
|
-
annotations: {
|
|
85
|
-
title: def.functionName,
|
|
86
|
-
// Hints can be derived from method names or hardcoded metadata in future
|
|
87
|
-
readOnlyHint: def.functionName.startsWith('get') || def.functionName.startsWith('is'),
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
}
|
package/src/tool-naming.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logic for stable, namespaced MCP tool names.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the canonical namespaced tool name for MCP.
|
|
7
|
-
* @example getCanonicalToolName('messages', 'sendText') -> 'messages.sendText'
|
|
8
|
-
*/
|
|
9
|
-
export function getCanonicalToolName(namespace: string, methodName: string): string {
|
|
10
|
-
return `${namespace}.${methodName}`;
|
|
11
|
-
}
|