Skip to main content

Quick Reference

Quick reference for using MCP (Model Context Protocol) servers with DelReact agents.

Basic Setup

import { ReactAgentBuilder } from "delreact-agent";

const agent = new ReactAgentBuilder({
geminiKey: process.env.GEMINI_KEY,
mcp: {
servers: [
{
name: "filesystem",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/path"]
}
]
}
}).build();

Configuration Options

OptionTypeDescription
serversMcpServerConfig[]Array of MCP server configurations
autoRegisterbooleanAuto-register tools (default: true)
operationTimeoutnumberTimeout in milliseconds

Server Configuration

FieldTypeRequiredDescription
namestringUnique server identifier
commandstringCommand to start server
argsstring[]Command arguments
envobjectEnvironment variables
timeoutnumberConnection timeout

Common Servers

Filesystem

{
name: "filesystem",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/allowed/path"]
}

Update Docs by Context7

{
name: "context7",
command: "npx",
args: ["-y", "@upstash/context7-mcp"],
}

SQLite

{
name: "sqlite",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-sqlite", "/db/path"]
}

Methods

MethodDescriptionReturns
addMcpServers(config)Add MCP configurationReactAgentBuilder
getMcpStatus()Get connection statusRecord<string, boolean>
cleanup()Disconnect all serversPromise<void>

Tool Naming

MCP tools are prefixed with server name:

  • Original: read_file
  • DelReact: filesystem--read_file

Example Usage

// 1. Configure agent with MCP
const agent = new ReactAgentBuilder({
geminiKey: process.env.GEMINI_KEY,
mcp: { servers: [/* configs */] }
}).build();

// 2. Use agent (MCP tools auto-available)
const result = await agent.invoke({
objective: "List and analyze project files"
});

// 3. Check status
console.log("MCP Status:", agent.getMcpStatus());

// 4. Cleanup
await agent.cleanup();

Error Handling

  • Connection failures don't break other servers
  • Tool execution errors are isolated
  • Timeouts prevent hanging operations
  • Invalid schemas handled gracefully

Best Practices

  1. ✅ Always call cleanup() when done
  2. ✅ Use appropriate timeouts
  3. ✅ Only connect to trusted servers
  4. ✅ Test connections independently
  5. ✅ Handle errors gracefully