MCP

Model Context Protocol client.

1 min readEdit this page

Connect

import { MCPClient } from '@restjs/ai'
 
const client = new MCPClient({ serverUrl: 'http://localhost:8080' })
await client.connect()

Tools

const tools = await client.listTools()
const result = await client.callTool('read_file', { path: '/etc/hosts' })

Use with agents

const mcpTools = await client.asAgentTools()
const agent = new Agent({ provider: ai, tools: [...builtIn, ...mcpTools] })

Note

MCP uses JSON-RPC 2.0 over HTTP. Protocol version 2024-11-05.