diff --git a/examples/nodejs/agent/agent.run.mcp.ts b/examples/nodejs/agent/agent.run.mcp.ts new file mode 100644 index 0000000..195b0a9 --- /dev/null +++ b/examples/nodejs/agent/agent.run.mcp.ts @@ -0,0 +1,34 @@ +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.agent.run({ + stream: false, + mcp_servers: [ + { + type: 'url', + name: 'deepwiki', + url: 'https://mcp.deepwiki.com/sse', + }, + ], + model: 'openai:gpt-4.1-mini', + apiKey: process.env.OPENAI_API_KEY!, + instructions: + 'You are a helpful assistant that help users summarize text.', + input: [ + { + role: 'user', + content: + 'What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?', + }, + ], + }); + + console.log('response: ', response.output); +} + +main(); diff --git a/packages/langbase/src/langbase/langbase.ts b/packages/langbase/src/langbase/langbase.ts index 5f6e566..e063719 100644 --- a/packages/langbase/src/langbase/langbase.ts +++ b/packages/langbase/src/langbase/langbase.ts @@ -39,18 +39,47 @@ export interface AgentRunOptionsBase { tools?: Tools[]; tool_choice?: 'auto' | 'required' | ToolChoice; parallel_tool_calls?: boolean; + mcp_servers?: McpServerSchema[]; reasoning_effort?: string | null; max_completion_tokens?: number; response_format?: ResponseFormat; customModelParams?: Record; } -export interface AgentRunOptions extends AgentRunOptionsBase { +export type AgentRunOptionsWithoutMcp = Omit< + AgentRunOptionsBase, + 'mcp_servers' +> & { stream?: false; -} +}; -export interface AgentRunOptionsStream extends AgentRunOptionsBase { +export type AgentRunOptionsWithMcp = AgentRunOptionsBase & { + mcp_servers: McpServerSchema[]; + stream: false; +}; + +export type AgentRunOptionsStreamT = Omit< + AgentRunOptionsBase, + 'mcp_servers' +> & { stream: true; +}; + +export type AgentRunOptions = + | AgentRunOptionsWithoutMcp + | AgentRunOptionsWithMcp; +export type AgentRunOptionsStream = AgentRunOptionsStreamT; + +export interface McpServerSchema { + name: string; + type: 'url'; + url: string; + authorization_token?: string; + tool_configuration?: { + allowed_tools?: string[]; + enabled?: boolean; + }; + custom_headers?: Record; } interface ChoiceGenerate { @@ -476,6 +505,13 @@ export interface ThreadMessagesBaseResponse { metadata: Record | {}; } +interface ChoiceGenerate { + index: number; + message: Message; + logprobs: boolean | null; + finish_reason: string; +} + export class Langbase { private request: Request; private apiKey: string;