1+ import json
2+
3+ from fastmcp import FastMCP
4+ from paper_manager import PaperManager
5+
6+ # Initialize MCP server and paper manager
7+ mcp = FastMCP ("AI Research Hub" )
8+ paper_manager = PaperManager ()
9+
10+ @mcp .tool (description = "Start researching a topic and get research ID" )
11+ async def research_topic (topic : str ) -> dict :
12+ """
13+ Create a new research entry for tracking papers and implementations
14+
15+ Args:
16+ topic: Research topic to investigate
17+
18+ Returns:
19+ Research entry details with tracking ID
20+ """
21+ research_entry = paper_manager .add_research_entry (topic )
22+
23+ return {
24+ "success" : True ,
25+ "topic" : topic ,
26+ "research_id" : research_entry ["id" ],
27+ "message" : f"Research entry #{ research_entry ['id' ]} created for '{ topic } '" ,
28+ "total_research_topics" : len (paper_manager .load_papers ())
29+ }
30+
31+ @mcp .tool (description = "Get GitHub search strategies for finding implementations" )
32+ async def get_github_searches (topic : str ) -> dict :
33+ """
34+ Generate GitHub search commands for finding code implementations
35+
36+ Args:
37+ topic: Research topic to find implementations for
38+
39+ Returns:
40+ GitHub search strategies and commands
41+ """
42+ return {
43+ "success" : True ,
44+ "topic" : topic ,
45+ "github_searches" : [f"{ topic } implementation" , f"{ topic } python" ],
46+ "commands" : [f"Search repos: { topic } stars:>10" ],
47+ "instructions" : "Use GitHub MCP with these search terms"
48+ }
49+
50+ @mcp .tool (description = "Add a paper to a research entry" )
51+ async def add_paper (research_id : int , title : str , authors : str = "" , url : str = "" ) -> dict :
52+ """
53+ Add a research paper to an existing research entry
54+
55+ Args:
56+ research_id: ID of the research entry to add to
57+ title: Title of the paper
58+ authors: Paper authors (optional)
59+ url: URL to the paper (optional)
60+
61+ Returns:
62+ Success status and details
63+ """
64+ paper_data = {
65+ "title" : title ,
66+ "authors" : authors ,
67+ "url" : url
68+ }
69+
70+ paper_manager .add_paper_to_research (research_id , paper_data )
71+
72+ return {
73+ "success" : True ,
74+ "research_id" : research_id ,
75+ "paper_added" : title ,
76+ "message" : f"Paper '{ title } ' added to research #{ research_id } "
77+ }
78+
79+ @mcp .tool (description = "Add a repository to a research entry" )
80+ async def add_repository (research_id : int , name : str , url : str = "" , stars : int = 0 ) -> dict :
81+ """
82+ Add a code repository to an existing research entry
83+
84+ Args:
85+ research_id: ID of the research entry to add to
86+ name: Repository name
87+ url: Repository URL (optional)
88+ stars: Star count (optional)
89+
90+ Returns:
91+ Success status and details
92+ """
93+ repo_data = {
94+ "name" : name ,
95+ "url" : url ,
96+ "stars" : stars
97+ }
98+
99+ paper_manager .add_repo_to_research (research_id , repo_data )
100+
101+ return {
102+ "success" : True ,
103+ "research_id" : research_id ,
104+ "repository_added" : name ,
105+ "message" : f"Repository '{ name } ' added to research #{ research_id } "
106+ }
107+
108+ @mcp .tool (description = "Update research status and add notes" )
109+ async def update_research_status (research_id : int , status : str , notes : str = "" ) -> dict :
110+ """
111+ Update the status of a research entry
112+
113+ Args:
114+ research_id: ID of the research entry to update
115+ status: New status (pending, active, complete)
116+ notes: Optional notes about the research progress
117+
118+ Returns:
119+ Success status and details
120+ """
121+ paper_manager .update_research_status (research_id , status , notes )
122+
123+ return {
124+ "success" : True ,
125+ "research_id" : research_id ,
126+ "status" : status ,
127+ "message" : f"Research #{ research_id } status updated to '{ status } '"
128+ }
129+
130+ @mcp .prompt (name = "research_workflow" )
131+ def research_workflow_prompt (topic : str ) -> str :
132+ """Complete research workflow for any topic"""
133+ return f"""Research Topic: { topic }
134+
135+ WORKFLOW:
136+ 1. research_topic(topic="{ topic } ") - Create research entry
137+ 2. Search HuggingFace papers: mcp_huggingface_paper_search(query="{ topic } ")
138+ 3. get_github_searches(topic="{ topic } ") - Get search strategies
139+ 4. Search GitHub repos: mcp_github_search_repositories(query="{ topic } ")
140+ 5. Add findings: add_paper() and add_repository()
141+ 6. update_research_status(research_id, "complete") - Mark done
142+ 7. Check research://status for dashboard
143+
144+ TOOLS: research_topic, add_paper, add_repository, get_github_searches, update_research_status
145+ GOAL: Link papers with implementations"""
146+
147+ @mcp .resource ("status://dashboard" )
148+ def research_status () -> str :
149+ """Current research status and saved topics"""
150+ summary = paper_manager .get_research_summary ()
151+ return json .dumps (summary , indent = 2 )
152+
153+ if __name__ == "__main__" :
154+ mcp .run ()
0 commit comments