mirror of
https://github.com/aljazceru/thoughtful-claude.git
synced 2026-01-26 09:54:57 +01:00
- Implemented MCP server with DeepSeek R1 reasoning integration - Added streaming response handling for reasoning content - Created comprehensive README with installation and usage guide - Added .gitignore for Python development - Configured environment variable handling for API keys The server enhances Claude's reasoning capabilities by providing access to DeepSeek R1's advanced reasoning engine through the MCP protocol.
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
from mcp.server.fastmcp import FastMCP
|
|
import httpx
|
|
import json
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
|
|
|
# Initialize FastMCP server
|
|
mcp = FastMCP("Thoughtful Claude DeepSeek Reasoner")
|
|
|
|
async def get_deepseek_response(query: str) -> str:
|
|
"""Get reasoning from DeepSeek API"""
|
|
async with httpx.AsyncClient() as client:
|
|
headers = {
|
|
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
payload = {
|
|
"model": "deepseek-reasoner",
|
|
"messages": [{"role": "user", "content": query}],
|
|
"stream": True,
|
|
"max_tokens": 1
|
|
}
|
|
|
|
async with client.stream(
|
|
"POST",
|
|
"https://api.deepseek.com/chat/completions",
|
|
headers=headers,
|
|
json=payload,
|
|
timeout=30000.0
|
|
) as response:
|
|
reasoning_chunks = []
|
|
async for line in response.aiter_lines():
|
|
if line.startswith("data: "):
|
|
data = line[6:]
|
|
if data == "[DONE]":
|
|
continue
|
|
try:
|
|
chunk_data = json.loads(data)
|
|
if content := chunk_data.get("choices", [{}])[0].get("delta", {}).get("reasoning_content", ""):
|
|
reasoning_chunks.append(content)
|
|
except:
|
|
continue
|
|
|
|
return " ".join(reasoning_chunks)
|
|
|
|
@mcp.tool()
|
|
async def reason(query: dict) -> str:
|
|
"""Process a query through DeepSeek's R1 reasoning engine and format for Claude.
|
|
|
|
Utilizes DeepSeek R1's advanced reasoning capabilities, which were developed through
|
|
large-scale reinforcement learning to naturally emerge powerful reasoning behaviors.
|
|
The reasoning output is wrapped in <ant_thinking> tags to integrate with Claude's
|
|
thought process.
|
|
|
|
Args:
|
|
query: Dictionary containing:
|
|
- context: Optional background information for the query
|
|
- question: The specific question to reason about
|
|
|
|
Returns:
|
|
str: DeepSeek's reasoning wrapped in <ant_thinking> tags for Claude's consumption
|
|
"""
|
|
try:
|
|
# Format the query from the input
|
|
context = query.get('context', '')
|
|
question = query.get('question', '')
|
|
full_query = f"{context}\n{question}" if context else question
|
|
|
|
# Get reasoning from DeepSeek
|
|
reasoning = await get_deepseek_response(full_query)
|
|
|
|
# Return the reasoning wrapped in ant_thinking tags
|
|
return f"<ant_thinking>\n{reasoning}\n</ant_thinking>"
|
|
except Exception as e:
|
|
return f"<ant_thinking>\nError: {str(e)}\n</ant_thinking>"
|
|
|
|
if __name__ == "__main__":
|
|
mcp.run()
|