Skip to content

MCP Server

The Distributed Knowledge MCP server provides a structured interface for interacting with the network using LLM's. This document explains how the MCP server works and the tools it provides.

What is MCP?

MCP (Model Context Protocol) is a standardized way for LLM systems to access external tools and capabilities. The Distributed Knowledge MCP server integrates the network's functionality into this protocol, making it accessible to compatible clients.

Server Configuration

The MCP server is initialized in dk/mcp/server.go with specific capabilities:

mcpServer := server.NewMCPServer(
    "openmined/dk-server",
    "1.0.0",
    server.WithResourceCapabilities(true, true),
    server.WithPromptCapabilities(true),
    server.WithLogging(),
)

The server is configured with:

  • Resource capabilities for file access
  • Prompt capabilities for text generation
  • Logging for diagnostic purposes

Available Tools

The MCP server exposes several tools that clients can use to interact with the Distributed Knowledge network:

Query Management Tools

  1. cqAskQuestion
  2. Sends a question to specified peers or broadcasts to the entire network
  3. Parameters:

    • question: The text of the question to send (required)
    • peers: List of peer identifiers to receive the question (required)
  4. cqListRequestedQueries

  5. Retrieves all requested queries, optionally filtered by status or sender
  6. Parameters:

    • status: Optional status filter (e.g., 'pending', 'accepted')
    • from: Optional sender filter (peer identifier)
  7. cqSummarizeAnswers

  8. Retrieves all peer responses for a given question and returns a summary
  9. Parameters:

    • related_question: The question for which to fetch responses (required)
    • detailed_answer: Flag for detail level (0 for concise, 1 for in-depth)
  10. cqUpdateEditAnswer

  11. Edits the content of a specific answer
  12. Parameters:
    • query_id: ID of the query to update (required)
    • new_answer: New answer content (required)

Approval Management Tools

  1. cqAddAutoApprovalCondition
  2. Adds a condition to the automatic approval system
  3. Parameters:

    • sentence: The condition to add (required)
  4. cqRemoveAutoApprovalCondition

  5. Removes a condition from the automatic approval system
  6. Parameters:

    • condition: The exact text of the condition to remove (required)
  7. cqListAutoApprovalConditions

  8. Lists all conditions in the automatic approval system
  9. No parameters required

  10. cqAcceptQuery

  11. Marks a pending query as 'accepted'
  12. Parameters:

    • id: Unique identifier of the query to accept (required)
  13. cqRejectQuery

  14. Marks a pending query as 'rejected'
  15. Parameters:
    • id: Unique identifier of the query to reject (required)

Knowledge Management Tools

  1. updateKnowledgeSources
  2. Updates knowledge sources by adding new content to the RAG database
  3. Parameters:
    • file_name: Name of the file to add
    • file_content: Content of the file
    • file_path: Path to an existing file

User Management Tools

  1. cqGetActiveUsers
  2. Retrieves lists of active and inactive users from the server
  3. Parameters:

    • flag: Boolean flag for additional options
  4. cqGetUserDescriptions

  5. Retrieves descriptions associated with a specific user
  6. Parameters:
    • user_id: ID of the user whose descriptions are requested (required)

Tool Implementation

Each tool is implemented as a Go function in dk/mcp/tools.go that:

  1. Receives a context and request parameters
  2. Performs the requested action
  3. Returns a result or error

Here's a simplified example of a tool handler:

func HandleAskTool(ctx context.Context, request mcp_lib.CallToolRequest) (*mcp_lib.CallToolResult, error) {
    // Extract arguments
    arguments := request.Params.Arguments
    message := arguments["question"].(string)

    // Process the request
    // ...

    // Return the result
    return &mcp_lib.CallToolResult{
        Content: []mcp_lib.Content{
            mcp_lib.TextContent{
                Type: "text",
                Text: "Query request sent successfully",
            },
        },
    }, nil
}

Using the MCP Server

To use the Distributed Knowledge MCP server with compatible clients:

  1. Configure the MCP client to connect to the server:
{
  "mcpServers": {
    "DistributedKnowledge": {
      "command": "dk",
      "args": [
        "-userId", "YourUsername",
        "-private", "/path/to/private_key",
        "-public", "/path/to/public_key",
        "-project_path", "/path/to/project",
        "-rag_sources", "/path/to/rag_sources.jsonl",
        "-server", "https://distributedknowledge.org"
      ]
    }
  }
}
  1. The client can then call tools using the MCP protocol:
{
  "name": "cqAskQuestion",
  "parameters": {
    "question": "What is quantum computing?",
    "peers": ["expertUser", "quantumResearcher"]
  }
}

Example Workflow

A typical workflow using the MCP server might look like:

  1. Check which users are active using cqGetActiveUsers
  2. Send a question to relevant peers using cqAskQuestion
  3. Wait for responses to arrive
  4. Retrieve and summarize the answers using cqSummarizeAnswers
  5. Optionally edit answers using cqUpdateEditAnswer

Security and Permissions

The MCP server respects the security model of the Distributed Knowledge network:

  • Tool calls are authenticated based on the user's credentials
  • Access to certain tools may be restricted based on permissions
  • Sensitive operations require proper authorization
  • All tool calls are logged for audit purposes

Error Handling

The MCP server provides detailed error information:

  • Invalid parameters result in clear error messages
  • Network or system failures are reported with context
  • Permission issues are explained with appropriate detail
  • Unexpected errors are logged for troubleshooting