MCP Integration Tutorial
This tutorial explains how to integrate Distributed Knowledge with Model Context Protocol (MCP) enabled systems. You'll learn how to set up Distributed Knowledge as an MCP server and use it with compatible LLM applications.
What is MCP?
Model Context Protocol (MCP) is a standardized way for LLM systems to access external tools and capabilities. By integrating Distributed Knowledge with MCP, you can:
- Access the collective intelligence of the network through standardized tools
- Incorporate network knowledge into LLM workflows
- Enable LLMs to query and interact with network peers
- Maintain a consistent interface across different systems
Prerequisites
Before starting, ensure you have:
- Distributed Knowledge installed (see Getting Started)
- An MCP-compatible host application (like Claude or another MCP-aware LLM interface)
- Basic familiarity with JSON configuration
Step 1: Configure Distributed Knowledge
First, ensure you have a properly configured Distributed Knowledge installation:
./dk -userId="mcp_user" \
-modelConfig="./config/model_config.json" \
-rag_sources="./data/knowledge_base.jsonl" \
-server="wss://distributedknowledge.org"
Test that it's working correctly by running a simple command:
You should receive a list of active users, confirming that your setup is working.
Step 2: Create MCP Configuration
Create an MCP configuration file that includes Distributed Knowledge as a server. Save this as mcp_config.json
:
{
"mcpServers": {
"DistributedKnowledge": {
"command": "/path/to/dk",
"args": [
"-userId", "mcp_user",
"-private", "/path/to/private_key.pem",
"-public", "/path/to/public_key.pem",
"-modelConfig", "/path/to/model_config.json",
"-rag_sources", "/path/to/rag_sources.jsonl",
"-server", "wss://distributedknowledge.org"
]
}
}
}
Adjust the paths and parameters to match your specific setup. This configuration tells the MCP host where to find the Distributed Knowledge executable and what parameters to use when launching it.
Step 3: Configure Your MCP Host
The exact steps depend on which MCP host you're using. Here are configurations for common hosts:
In your Claude.ai settings, add the MCP configuration:
- Go to Settings > Experimental Features
- Enable "Model Context Protocol"
- Upload your
mcp_config.json
file - Restart Claude if necessary
For a custom MCP host, follow that system's specific instructions for adding MCP servers, referencing your mcp_config.json
file.
Step 4: Test the Integration
Now that you've configured your MCP host to use Distributed Knowledge, test the integration:
- Open your MCP host application
- Start a new conversation
- Ask the LLM to use the Distributed Knowledge tools
Example prompt:
The LLM should:
- Recognize this as a task for Distributed Knowledge
- Use the
cqGetActiveUsers
tool - Return the results to you
Step 5: Use Advanced MCP Functions
Now try more advanced functions:
Ask a Network Question
Prompt:
The LLM should:
- Use the
cqAskQuestion
tool - Broadcast the question to the network
- Inform you that the question has been sent
Retrieve and Summarize Answers
After waiting for responses, ask:
The LLM should:
- Use the
cqListRequestedQueries
tool to check for responses - Use the
cqSummarizeAnswers
tool to create a summary - Present the results to you
Update Knowledge Base
You can also add new information to your knowledge base:
Please add this information to the Distributed Knowledge base: "In 2025, researchers achieved a quantum advantage for the first time in protein folding simulations, using a 300-qubit quantum computer."
The LLM should:
- Use the
updateKnowledgeSources
tool - Add the information to your RAG sources
- Confirm the addition
Step 6: Create Tool Sequences
The real power of MCP integration comes from combining tools into useful sequences. Here's an example workflow:
I'd like to do research on climate adaptation strategies. Can you:
1. Check which experts on climate are active on the network
2. Send them a specific question about regional adaptation approaches
3. Wait for responses and then summarize the different perspectives
The LLM should execute this multi-step process using the appropriate sequence of tools.
Advanced MCP Integration
Custom Tool Selection
You can specifically ask the LLM to use certain Distributed Knowledge tools:
Use the Distributed Knowledge tool cqGetUserDescriptions to get information about the user "climate_scientist".
Tool-Specific Parameters
Provide specific parameters for tool calls:
Please use the cqSummarizeAnswers tool with detailed_answer set to 1 to get comprehensive information about climate adaptation strategies.
Approval System Management
Manage your automatic approval system:
Please add an automatic approval rule to accept all questions related to climate science from verified researchers.
Integration Best Practices
- Start Simple: Begin with basic tool calls before complex sequences
- Be Specific: Clearly state what you want the LLM to do with the tools
- Provide Context: Give enough background so the LLM knows which tools to use
- Verify Results: Double-check important information returned via the tools
- Use Appropriate Tools: Learn which tools are best for specific tasks
Troubleshooting
Common Issues
Issue | Solution |
---|---|
"Tool not found" errors | Verify your MCP configuration file and paths |
Connection failures | Check that Distributed Knowledge is properly connected to the server |
Permission errors | Ensure file permissions are correct for all paths in your configuration |
Tool timeouts | For complex operations, break them into smaller steps |
Diagnostic Steps
If you encounter problems:
- Check that Distributed Knowledge runs properly outside of MCP
- Verify your MCP configuration syntax
- Look for error messages in your MCP host's logs
- Try restarting both Distributed Knowledge and your MCP host
- Simplify your requests until you identify the failing component
Next Steps
Now that you've integrated Distributed Knowledge with MCP, consider:
- Exploring all available MCP tools
- Setting up specialized knowledge domains
- Creating custom workflows for common tasks
- Integrating with multiple LLM systems
MCP integration makes Distributed Knowledge's capabilities available in a standardized way across different LLM platforms, enabling powerful collaborative intelligence workflows.