Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/nodejs/agent/agent.run.mcp.ts
Original file line number Diff line number Diff line change
@@ -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();
42 changes: 39 additions & 3 deletions packages/langbase/src/langbase/langbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
}

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<string, string>;
}

interface ChoiceGenerate {
Expand Down Expand Up @@ -476,6 +505,13 @@ export interface ThreadMessagesBaseResponse {
metadata: Record<string, string> | {};
}

interface ChoiceGenerate {
index: number;
message: Message;
logprobs: boolean | null;
finish_reason: string;
}

export class Langbase {
private request: Request;
private apiKey: string;
Expand Down
Loading