Skip to content

Commit 3a61413

Browse files
arre-ankitmsaaddev
andauthored
📦 NEW: MCP support in agent run (#105)
* 📦 NEW: MCP support in agent run * 🐛 FIX: formatting * 👌 IMPROVE: Review by SI --------- Co-authored-by: msaaddev <[email protected]>
1 parent 2e775a0 commit 3a61413

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed
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+
const response = await langbase.agent.run({
10+
stream: false,
11+
mcp_servers: [
12+
{
13+
type: 'url',
14+
name: 'deepwiki',
15+
url: 'https://mcp.deepwiki.com/sse',
16+
},
17+
],
18+
model: 'openai:gpt-4.1-mini',
19+
apiKey: process.env.OPENAI_API_KEY!,
20+
instructions:
21+
'You are a helpful assistant that help users summarize text.',
22+
input: [
23+
{
24+
role: 'user',
25+
content:
26+
'What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?',
27+
},
28+
],
29+
});
30+
31+
console.log('response: ', response.output);
32+
}
33+
34+
main();

packages/langbase/src/langbase/langbase.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,47 @@ 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<
50+
AgentRunOptionsBase,
51+
'mcp_servers'
52+
> & {
4953
stream?: false;
50-
}
54+
};
5155

52-
export interface AgentRunOptionsStream extends AgentRunOptionsBase {
56+
export type AgentRunOptionsWithMcp = AgentRunOptionsBase & {
57+
mcp_servers: McpServerSchema[];
58+
stream: false;
59+
};
60+
61+
export type AgentRunOptionsStreamT = Omit<
62+
AgentRunOptionsBase,
63+
'mcp_servers'
64+
> & {
5365
stream: true;
66+
};
67+
68+
export type AgentRunOptions =
69+
| AgentRunOptionsWithoutMcp
70+
| AgentRunOptionsWithMcp;
71+
export type AgentRunOptionsStream = AgentRunOptionsStreamT;
72+
73+
export interface McpServerSchema {
74+
name: string;
75+
type: 'url';
76+
url: string;
77+
authorization_token?: string;
78+
tool_configuration?: {
79+
allowed_tools?: string[];
80+
enabled?: boolean;
81+
};
82+
custom_headers?: Record<string, string>;
5483
}
5584

5685
interface ChoiceGenerate {
@@ -476,6 +505,13 @@ export interface ThreadMessagesBaseResponse {
476505
metadata: Record<string, string> | {};
477506
}
478507

508+
interface ChoiceGenerate {
509+
index: number;
510+
message: Message;
511+
logprobs: boolean | null;
512+
finish_reason: string;
513+
}
514+
479515
export class Langbase {
480516
private request: Request;
481517
private apiKey: string;

0 commit comments

Comments
 (0)