Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
MCP Tools
Integrate Model Context Protocol (MCP) servers to extend agent capabilities with external tools, resources, and prompts.
Quick Start
import { Agent, createMCP } from 'praisonai-ts';
// Connect to MCP server
const mcp = await createMCP({
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path/to/dir'],
},
});
// Get tools from MCP server
const tools = await mcp.tools();
// Create agent with MCP tools
const agent = new Agent({
name: 'FileAgent',
instructions: 'You help manage files.',
tools: Object.values(tools),
});
const response = await agent.chat('List all files in the directory');
Transport Types
Stdio (Local Servers)
const mcp = await createMCP({
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path'],
env: { NODE_ENV: 'production' },
},
});
SSE (Server-Sent Events)
const mcp = await createMCP({
transport: {
type: 'sse',
url: 'https://mcp-server.example.com/sse',
headers: { Authorization: 'Bearer token' },
},
});
HTTP
const mcp = await createMCP({
transport: {
type: 'http',
url: 'https://mcp-server.example.com/api',
headers: { 'X-API-Key': 'key' },
},
});
WebSocket
const mcp = await createMCP({
transport: {
type: 'websocket',
url: 'wss://mcp-server.example.com/ws',
},
});
OAuth Authentication
import { createMCP, type OAuthClientProvider } from 'praisonai-ts';
const oauthProvider: OAuthClientProvider = {
getAccessToken: async () => {
return await getStoredToken();
},
refreshToken: async () => {
return await refreshOAuthToken();
},
};
const mcp = await createMCP({
transport: {
type: 'http',
url: 'https://mcp-server.example.com/api',
authProvider: oauthProvider,
},
});
Resources
Access resources from MCP servers:
// List available resources
const resources = await mcp.listResources();
console.log('Resources:', resources);
// Read a resource
const content = await mcp.readResource('file:///path/to/file.txt');
console.log('Content:', content.text);
Prompts
Use prompts from MCP servers:
// List available prompts
const prompts = await mcp.listPrompts();
console.log('Prompts:', prompts);
// Get a prompt
const prompt = await mcp.getPrompt('summarize', { length: 'short' });
console.log('Prompt messages:', prompt.messages);
Popular MCP Servers
| Server | Package | Description |
|---|
| Filesystem | @modelcontextprotocol/server-filesystem | File operations |
| GitHub | @modelcontextprotocol/server-github | GitHub API |
| Slack | @modelcontextprotocol/server-slack | Slack integration |
| PostgreSQL | @modelcontextprotocol/server-postgres | Database queries |
| Brave Search | @modelcontextprotocol/server-brave-search | Web search |
Example: Filesystem Server
import { Agent, createMCP } from 'praisonai-ts';
const mcp = await createMCP({
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', './documents'],
},
});
const tools = await mcp.tools();
const agent = new Agent({
name: 'FileManager',
instructions: 'You help manage files and directories.',
tools: Object.values(tools),
});
await agent.chat('Create a new file called notes.txt with "Hello World"');
Example: GitHub Server
const mcp = await createMCP({
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN },
},
});
const tools = await mcp.tools();
const agent = new Agent({
name: 'GitHubAgent',
instructions: 'You help with GitHub operations.',
tools: Object.values(tools),
});
await agent.chat('List my recent repositories');
Cleanup
Always close MCP connections when done:
import { closeMCPClient, closeAllMCPClients } from 'praisonai-ts';
// Close specific client
await closeMCPClient('my-client-id');
// Close all clients
await closeAllMCPClients();
Environment Variables
| Variable | Required | Description |
|---|
OPENAI_API_KEY | Yes | For the agent |
| Server-specific | Varies | MCP server requirements |
Best Practices
- Close connections - Always close MCP clients when done
- Handle errors - MCP servers may fail or timeout
- Use appropriate transport - Stdio for local, HTTP/SSE for remote
- Secure credentials - Use OAuth for authenticated servers
- Tools - Tool system overview
- Agent - Agent configuration