@smithery/sdk 1.5.8 → 1.5.10
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/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- package/dist/shared/config.d.ts +1 -0
- package/dist/shared/config.js +1 -1
- package/package.json +2 -5
- package/dist/client/integrations/ai-sdk.d.ts +0 -15
- package/dist/client/integrations/ai-sdk.js +0 -39
- package/dist/client/integrations/llm/anthropic.d.ts +0 -12
- package/dist/client/integrations/llm/anthropic.js +0 -48
- package/dist/client/integrations/llm/openai.d.ts +0 -19
- package/dist/client/integrations/llm/openai.js +0 -48
- package/dist/client/integrations/wrap-error.d.ts +0 -5
- package/dist/client/integrations/wrap-error.js +0 -24
- package/dist/client/transport.d.ts +0 -9
- package/dist/client/transport.js +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export * from "./shared/config.js";
|
|
2
2
|
export * from "./shared/patch.js";
|
|
3
|
-
export * from "./client/transport.js";
|
|
4
|
-
export * from "./client/integrations/ai-sdk.js";
|
|
5
|
-
export * from "./client/integrations/wrap-error.js";
|
|
6
3
|
export { createStatefulServer, type StatefulServerOptions, } from "./server/stateful.js";
|
|
7
4
|
export * from "./server/session.js";
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
// Shared utilities
|
|
5
5
|
export * from "./shared/config.js";
|
|
6
6
|
export * from "./shared/patch.js";
|
|
7
|
-
// Client-side helpers
|
|
8
|
-
export * from "./client/transport.js";
|
|
9
|
-
export * from "./client/integrations/ai-sdk.js";
|
|
10
|
-
export * from "./client/integrations/wrap-error.js";
|
|
11
7
|
// Server-side helpers (selective to avoid duplicate type names)
|
|
12
8
|
export { createStatefulServer, } from "./server/stateful.js";
|
|
13
9
|
export * from "./server/session.js";
|
package/dist/shared/config.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface SmitheryUrlOptions {
|
|
|
5
5
|
profile?: string;
|
|
6
6
|
config?: object;
|
|
7
7
|
}
|
|
8
|
+
export declare function appendConfigAsDotParams(url: URL, config: unknown): void;
|
|
8
9
|
/**
|
|
9
10
|
* Creates a URL to connect to the Smithery MCP server.
|
|
10
11
|
* @param baseUrl The base URL of the Smithery server
|
package/dist/shared/config.js
CHANGED
|
@@ -4,7 +4,7 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
4
4
|
function isPlainObject(value) {
|
|
5
5
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
6
|
}
|
|
7
|
-
function appendConfigAsDotParams(url, config) {
|
|
7
|
+
export function appendConfigAsDotParams(url, config) {
|
|
8
8
|
function add(pathParts, value) {
|
|
9
9
|
if (Array.isArray(value)) {
|
|
10
10
|
for (let index = 0; index < value.length; index++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithery/sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.10",
|
|
4
4
|
"description": "SDK to develop with Smithery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,14 +20,11 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@modelcontextprotocol/sdk": "^1.15.0",
|
|
25
|
-
"ai": "^4.3.15",
|
|
23
|
+
"@modelcontextprotocol/sdk": "^1.18.0",
|
|
26
24
|
"express": "^5.1.0",
|
|
27
25
|
"json-schema": "^0.4.0",
|
|
28
26
|
"lodash": "^4.17.21",
|
|
29
27
|
"okay-error": "^1.0.3",
|
|
30
|
-
"openai": "^4.0.0",
|
|
31
28
|
"uuid": "^11.0.3",
|
|
32
29
|
"zod": "^3.23.8",
|
|
33
30
|
"zod-to-json-schema": "^3.24.1"
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import { type Tool } from "ai";
|
|
3
|
-
type ToolClient = Pick<Client, "listTools" | "callTool" | "setNotificationHandler">;
|
|
4
|
-
/**
|
|
5
|
-
* Watches the MCP client for tool changes and updates the tools object accordingly.
|
|
6
|
-
* @param client The MCP client to watch
|
|
7
|
-
* @returns A record of tool names to their implementations
|
|
8
|
-
*/
|
|
9
|
-
export declare function watchTools(client: ToolClient): Promise<Record<string, Tool>>;
|
|
10
|
-
/**
|
|
11
|
-
* Returns a set of wrapped AI SDK tools from the MCP server.
|
|
12
|
-
* @returns A record of tool names to their implementations
|
|
13
|
-
*/
|
|
14
|
-
export declare function listTools(client: ToolClient): Promise<Record<string, Tool>>;
|
|
15
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { jsonSchema, tool, } from "ai";
|
|
3
|
-
/**
|
|
4
|
-
* Watches the MCP client for tool changes and updates the tools object accordingly.
|
|
5
|
-
* @param client The MCP client to watch
|
|
6
|
-
* @returns A record of tool names to their implementations
|
|
7
|
-
*/
|
|
8
|
-
export async function watchTools(client) {
|
|
9
|
-
const tools = {};
|
|
10
|
-
client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
|
|
11
|
-
Object.assign(tools, await listTools(client));
|
|
12
|
-
});
|
|
13
|
-
Object.assign(tools, await listTools(client));
|
|
14
|
-
return tools;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Returns a set of wrapped AI SDK tools from the MCP server.
|
|
18
|
-
* @returns A record of tool names to their implementations
|
|
19
|
-
*/
|
|
20
|
-
export async function listTools(client) {
|
|
21
|
-
const tools = {};
|
|
22
|
-
const listToolsResult = await client.listTools();
|
|
23
|
-
for (const { name, description, inputSchema } of listToolsResult.tools) {
|
|
24
|
-
const parameters = jsonSchema(inputSchema);
|
|
25
|
-
tools[name] = tool({
|
|
26
|
-
description,
|
|
27
|
-
parameters,
|
|
28
|
-
execute: async (args, options) => {
|
|
29
|
-
options?.abortSignal?.throwIfAborted();
|
|
30
|
-
const result = await client.callTool({
|
|
31
|
-
name,
|
|
32
|
-
arguments: args,
|
|
33
|
-
});
|
|
34
|
-
return result;
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return tools;
|
|
39
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Message, MessageParam, Tool } from "@anthropic-ai/sdk/resources/index.js";
|
|
2
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
-
/**
|
|
5
|
-
* Adapt an MCP client so it works seamlessly with Anthropic messages
|
|
6
|
-
*/
|
|
7
|
-
export declare class AnthropicChatAdapter {
|
|
8
|
-
private client;
|
|
9
|
-
constructor(client: Pick<Client, "callTool" | "listTools">);
|
|
10
|
-
listTools(): Promise<Tool[]>;
|
|
11
|
-
callTool(response: Message, options?: RequestOptions): Promise<MessageParam[]>;
|
|
12
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Adapt an MCP client so it works seamlessly with Anthropic messages
|
|
4
|
-
*/
|
|
5
|
-
export class AnthropicChatAdapter {
|
|
6
|
-
constructor(client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
}
|
|
9
|
-
async listTools() {
|
|
10
|
-
const toolResult = await this.client.listTools();
|
|
11
|
-
return toolResult.tools.map(tool => ({
|
|
12
|
-
name: tool.name,
|
|
13
|
-
description: tool.description,
|
|
14
|
-
input_schema: tool.inputSchema,
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
// TODO: Support streaming
|
|
18
|
-
async callTool(response, options) {
|
|
19
|
-
const content = response.content;
|
|
20
|
-
if (!content || content.length === 0) {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
// Find tool calls in the message content
|
|
24
|
-
const toolCalls = content.filter(part => part.type === "tool_use");
|
|
25
|
-
if (toolCalls.length === 0) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
// Run parallel tool call
|
|
29
|
-
const results = await Promise.all(toolCalls.map(async (toolCall) => {
|
|
30
|
-
return await this.client.callTool({
|
|
31
|
-
name: toolCall.name,
|
|
32
|
-
arguments: toolCall.input,
|
|
33
|
-
}, CallToolResultSchema, options);
|
|
34
|
-
}));
|
|
35
|
-
return [
|
|
36
|
-
{
|
|
37
|
-
role: "user",
|
|
38
|
-
content: results.map((result, index) => ({
|
|
39
|
-
tool_use_id: toolCalls[index].id,
|
|
40
|
-
type: "tool_result",
|
|
41
|
-
// TODO: Find a way to remove the any
|
|
42
|
-
content: result.content.filter((part) => part.type === "text"),
|
|
43
|
-
is_error: Boolean(result.isError),
|
|
44
|
-
})),
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { OpenAI } from "openai";
|
|
2
|
-
import type { ChatCompletionTool, ChatCompletionToolMessageParam } from "openai/resources/index.js";
|
|
3
|
-
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
4
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
|
-
interface OpenAIAdapterOptions {
|
|
6
|
-
strict?: boolean;
|
|
7
|
-
truncateDescriptionLength?: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Adapt an MCP client so it works seamlessly with OpenAI chat completions
|
|
11
|
-
*/
|
|
12
|
-
export declare class OpenAIChatAdapter {
|
|
13
|
-
private client;
|
|
14
|
-
private options;
|
|
15
|
-
constructor(client: Pick<Client, "callTool" | "listTools">, options?: OpenAIAdapterOptions);
|
|
16
|
-
listTools(): Promise<ChatCompletionTool[]>;
|
|
17
|
-
callTool(response: OpenAI.Chat.Completions.ChatCompletion, options?: RequestOptions): Promise<ChatCompletionToolMessageParam[]>;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Adapt an MCP client so it works seamlessly with OpenAI chat completions
|
|
4
|
-
*/
|
|
5
|
-
export class OpenAIChatAdapter {
|
|
6
|
-
constructor(client, options = {
|
|
7
|
-
// Restriction enforced by OpenAI
|
|
8
|
-
truncateDescriptionLength: 1024,
|
|
9
|
-
}) {
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
async listTools() {
|
|
14
|
-
const toolResult = await this.client.listTools();
|
|
15
|
-
return toolResult.tools.map(tool => ({
|
|
16
|
-
type: "function",
|
|
17
|
-
function: {
|
|
18
|
-
name: tool.name,
|
|
19
|
-
description: tool.description?.slice(0, this.options?.truncateDescriptionLength),
|
|
20
|
-
parameters: tool.inputSchema,
|
|
21
|
-
strict: this.options?.strict ?? false,
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
// TODO: Support streaming
|
|
26
|
-
async callTool(response, options) {
|
|
27
|
-
if (response.choices.length !== 1) {
|
|
28
|
-
// TODO: Support `n`
|
|
29
|
-
throw new Error("Multiple choices not supported");
|
|
30
|
-
}
|
|
31
|
-
const choice = response.choices[0];
|
|
32
|
-
if (!choice?.message?.tool_calls) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
const toolCalls = choice.message.tool_calls;
|
|
36
|
-
const results = await Promise.all(toolCalls.map(async (toolCall) => {
|
|
37
|
-
return await this.client.callTool({
|
|
38
|
-
name: toolCall.function.name,
|
|
39
|
-
arguments: JSON.parse(toolCall.function.arguments),
|
|
40
|
-
}, CallToolResultSchema, options);
|
|
41
|
-
}));
|
|
42
|
-
return results.map((result, index) => ({
|
|
43
|
-
role: "tool",
|
|
44
|
-
content: result.content,
|
|
45
|
-
tool_call_id: toolCalls[index].id,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { patch } from "../../shared/patch.js";
|
|
3
|
-
/**
|
|
4
|
-
* Wraps each tool call so any errors get sent back to the LLM instead of throwing
|
|
5
|
-
*/
|
|
6
|
-
export function wrapError(client) {
|
|
7
|
-
patch(client, "callTool", callTool => async (params, resultSchema = CallToolResultSchema, options) => {
|
|
8
|
-
try {
|
|
9
|
-
return await callTool(params, resultSchema, options);
|
|
10
|
-
}
|
|
11
|
-
catch (err) {
|
|
12
|
-
return {
|
|
13
|
-
content: [
|
|
14
|
-
{
|
|
15
|
-
type: "text",
|
|
16
|
-
text: JSON.stringify(err, Object.getOwnPropertyNames(err)),
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
isError: true,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return client;
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
2
|
-
import { type SmitheryUrlOptions } from "../shared/config.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a transport to connect to the Smithery server
|
|
5
|
-
* @param baseUrl The URL of the Smithery server (without trailing slash or protocol)
|
|
6
|
-
* @param options Optional configuration object
|
|
7
|
-
* @returns Transport
|
|
8
|
-
*/
|
|
9
|
-
export declare function createTransport(baseUrl: string, options?: SmitheryUrlOptions): StreamableHTTPClientTransport;
|
package/dist/client/transport.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
2
|
-
import { createSmitheryUrl } from "../shared/config.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a transport to connect to the Smithery server
|
|
5
|
-
* @param baseUrl The URL of the Smithery server (without trailing slash or protocol)
|
|
6
|
-
* @param options Optional configuration object
|
|
7
|
-
* @returns Transport
|
|
8
|
-
*/
|
|
9
|
-
export function createTransport(baseUrl, options) {
|
|
10
|
-
return new StreamableHTTPClientTransport(createSmitheryUrl(baseUrl, options));
|
|
11
|
-
}
|