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
- cqAskQuestion
- Sends a question to specified peers or broadcasts to the entire network
-
Parameters:
question
: The text of the question to send (required)peers
: List of peer identifiers to receive the question (required)
-
cqListRequestedQueries
- Retrieves all requested queries, optionally filtered by status or sender
-
Parameters:
status
: Optional status filter (e.g., 'pending', 'accepted')from
: Optional sender filter (peer identifier)
-
cqSummarizeAnswers
- Retrieves all peer responses for a given question and returns a summary
-
Parameters:
related_question
: The question for which to fetch responses (required)detailed_answer
: Flag for detail level (0 for concise, 1 for in-depth)
-
cqUpdateEditAnswer
- Edits the content of a specific answer
- Parameters:
query_id
: ID of the query to update (required)new_answer
: New answer content (required)
Approval Management Tools
- cqAddAutoApprovalCondition
- Adds a condition to the automatic approval system
-
Parameters:
sentence
: The condition to add (required)
-
cqRemoveAutoApprovalCondition
- Removes a condition from the automatic approval system
-
Parameters:
condition
: The exact text of the condition to remove (required)
-
cqListAutoApprovalConditions
- Lists all conditions in the automatic approval system
-
No parameters required
-
cqAcceptQuery
- Marks a pending query as 'accepted'
-
Parameters:
id
: Unique identifier of the query to accept (required)
-
cqRejectQuery
- Marks a pending query as 'rejected'
- Parameters:
id
: Unique identifier of the query to reject (required)
Knowledge Management Tools
- updateKnowledgeSources
- Updates knowledge sources by adding new content to the RAG database
- Parameters:
file_name
: Name of the file to addfile_content
: Content of the filefile_path
: Path to an existing file
User Management Tools
- cqGetActiveUsers
- Retrieves lists of active and inactive users from the server
-
Parameters:
flag
: Boolean flag for additional options
-
cqGetUserDescriptions
- Retrieves descriptions associated with a specific user
- 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:
- Receives a context and request parameters
- Performs the requested action
- 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:
- 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"
]
}
}
}
- 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:
- Check which users are active using
cqGetActiveUsers
- Send a question to relevant peers using
cqAskQuestion
- Wait for responses to arrive
- Retrieve and summarize the answers using
cqSummarizeAnswers
- 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