0.3.7 • Published 5 months ago

@daydreamsai/mcp v0.3.7

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

MCP Integration for Daydreams

This module provides integration with the Model Context Protocol (MCP), allowing Daydreams agents to connect to any MCP server and access its resources, prompts, and tools.

Overview

The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This integration enables Daydreams agents to:

  • Connect to multiple MCP servers simultaneously
  • Access resources from MCP servers
  • Execute tools provided by MCP servers
  • Use prompts defined on MCP servers

Usage

Basic Setup

To connect your Daydreams agent to one or more MCP servers, add the MCP extension to your agent configuration:

import { createDreams } from "@daydreams/core";
import { createMcpExtension } from "@daydreams/core/mcp";

const agent = createDreams({
  // ... other agent configuration
  extensions: [
    createMcpExtension([
      {
        id: "sqlite-explorer",
        name: "SQLite Explorer",
        transport: {
          type: "stdio",
          command: "node",
          args: ["path/to/sqlite-explorer-server.js"],
        },
      },
      {
        id: "web-search",
        name: "Web Search Service",
        transport: {
          type: "sse",
          serverUrl: "http://localhost:3001",
        },
      },
    ]),
    // ... other extensions
  ],
});

await agent.start();

Available Actions

The MCP extension adds the following actions to your agent:

List MCP Servers

// List all connected MCP servers
const result = await agent.callTool({
  name: "mcp.listServers",
  arguments: {},
});

List Prompts

// List all prompts available on a specific MCP server
const result = await agent.callTool({
  name: "mcp.listPrompts",
  arguments: {
    serverId: "sqlite-explorer",
  },
});

Get a Prompt

// Get a specific prompt from an MCP server
const result = await agent.callTool({
  name: "mcp.getPrompt",
  arguments: {
    serverId: "sqlite-explorer",
    name: "query-database",
    arguments: {
      table: "users",
    },
  },
});

List Resources

// List all resources available on a specific MCP server
const result = await agent.callTool({
  name: "mcp.listResources",
  arguments: {
    serverId: "sqlite-explorer",
  },
});

Read a Resource

// Read a specific resource from an MCP server
const result = await agent.callTool({
  name: "mcp.readResource",
  arguments: {
    serverId: "sqlite-explorer",
    uri: "schema://main",
  },
});

Call a Tool

// Call a tool on an MCP server
const result = await agent.callTool({
  name: "mcp.callTool",
  arguments: {
    serverId: "sqlite-explorer",
    name: "query",
    arguments: {
      sql: "SELECT * FROM users LIMIT 10",
    },
  },
});

Transport Types

The MCP extension supports two types of transports:

stdio

Use this for local MCP servers that run as separate processes:

{
  id: "local-server",
  name: "Local MCP Server",
  transport: {
    type: "stdio",
    command: "node",
    args: ["server.js"],
  },
}

SSE (Server-Sent Events)

Use this for remote MCP servers that expose an HTTP API with SSE:

{
  id: "remote-server",
  name: "Remote MCP Server",
  transport: {
    type: "sse",
    serverUrl: "http://example.com",
    sseEndpoint: "/sse",      // Optional, defaults to "/sse"
    messageEndpoint: "/messages", // Optional, defaults to "/messages"
  },
}

Error Handling

All MCP actions return an error field if something goes wrong. You can check for this field to handle errors:

const result = await agent.callTool({
  name: "mcp.callTool",
  arguments: {
    serverId: "sqlite-explorer",
    name: "query",
    arguments: {
      sql: "SELECT * FROM users LIMIT 10",
    },
  },
});

if (result.error) {
  console.error("Error calling MCP tool:", result.error);
} else {
  console.log("Tool result:", result.result);
}
0.3.7

5 months ago

0.3.7-alpha.7

5 months ago

0.3.7-alpha.6

5 months ago

0.3.7-alpha.5

5 months ago

0.3.7-alpha.4

5 months ago

0.3.7-alpha.3

5 months ago

0.3.7-alpha.2

5 months ago

0.3.6

6 months ago

0.3.5

6 months ago

0.3.4

6 months ago

0.3.3

6 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.3.0

6 months ago

0.3.0-alpha.2

6 months ago

0.3.0-alpha.1

7 months ago

0.3.0-alpha.0

7 months ago