Skip to content

Commit 053a806

Browse files
committed
📦 NEW: MCP support in agent run
1 parent 2e775a0 commit 053a806

2 files changed

Lines changed: 65 additions & 3 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'dotenv/config';
2+
import { Langbase } from 'langbase';
3+
4+
const langbase = new Langbase({
5+
apiKey: process.env.LANGBASE_API_KEY!,
6+
});
7+
8+
async function main() {
9+
10+
const response = await langbase.agent.run({
11+
stream: false,
12+
mcp_servers: [
13+
{
14+
type: 'url',
15+
name: 'deepwiki',
16+
url: 'https://mcp.deepwiki.com/sse',
17+
},
18+
],
19+
model: 'openai:gpt-4.1-mini',
20+
apiKey: process.env.LLM_API_KEY!,
21+
instructions: 'You are a helpful assistant that help users summarize text.',
22+
input: [
23+
{
24+
role: 'user',
25+
content: 'What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?',
26+
},
27+
],
28+
});
29+
30+
console.log('response: ', response.output);
31+
}
32+
33+
main();
34+

packages/langbase/src/langbase/langbase.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,39 @@ export interface AgentRunOptionsBase {
3939
tools?: Tools[];
4040
tool_choice?: 'auto' | 'required' | ToolChoice;
4141
parallel_tool_calls?: boolean;
42+
mcp_servers?: McpServerSchema[];
4243
reasoning_effort?: string | null;
4344
max_completion_tokens?: number;
4445
response_format?: ResponseFormat;
4546
customModelParams?: Record<string, any>;
4647
}
4748

48-
export interface AgentRunOptions extends AgentRunOptionsBase {
49+
export type AgentRunOptionsWithoutMcp = Omit<AgentRunOptionsBase, 'mcp_servers'> & {
4950
stream?: false;
50-
}
51+
};
52+
53+
export type AgentRunOptionsWithMcp = AgentRunOptionsBase & {
54+
mcp_servers: McpServerSchema[];
55+
stream: false;
56+
};
5157

52-
export interface AgentRunOptionsStream extends AgentRunOptionsBase {
58+
export type AgentRunOptionsStreamT = Omit<AgentRunOptionsBase, 'mcp_servers'> & {
5359
stream: true;
60+
};
61+
62+
export type AgentRunOptions = AgentRunOptionsWithoutMcp | AgentRunOptionsWithMcp;
63+
export type AgentRunOptionsStream = AgentRunOptionsStreamT;
64+
65+
export interface McpServerSchema {
66+
name: string;
67+
type: 'url';
68+
url: string;
69+
authorization_token?: string;
70+
tool_configuration?: {
71+
allowed_tools?: string[];
72+
enabled?: boolean;
73+
}
74+
custom_headers?: Record<string, string>
5475
}
5576

5677
interface ChoiceGenerate {
@@ -476,6 +497,13 @@ export interface ThreadMessagesBaseResponse {
476497
metadata: Record<string, string> | {};
477498
}
478499

500+
interface ChoiceGenerate {
501+
index: number;
502+
message: Message;
503+
logprobs: boolean | null;
504+
finish_reason: string;
505+
}
506+
479507
export class Langbase {
480508
private request: Request;
481509
private apiKey: string;

0 commit comments

Comments
 (0)