File size: 2,449 Bytes
1b38924
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import tools
import database
from mcp.server.fastmcp import FastMCP
    
HAS_MCP = True

if HAS_MCP:
    mcp_app = FastMCP("Academic-Research-Assistant-MCP")

    @mcp_app.tool()
    def search_arxiv(query: str, max_results: int = 5) -> str:
        """ArXiv platformundan verilen akademik konu veya anahtar kelimelere göre makaleleri arar."""
        res = tools.search_arxiv_papers(query=query, max_results=max_results)
        return str(res)

    @mcp_app.tool()
    def search_openalex(query: str, limit: int = 5) -> str:
        """Semantic Scholar platformundan atıf sayıları (citations) ile makale arar."""
        res = tools.search_openalex(query=query, limit=limit)
        return str(res)

    @mcp_app.tool()
    def save_paper(paper_id: str, title: str, authors: str = "", summary: str = "", url: str = "", published_year: str = "", tags: str = "genel") -> str:
        """Makaleyi SQLite kişisel kütüphane veritabanına kaydeder."""
        res = database.save_paper(paper_id=paper_id, title=title, authors=authors, summary=summary, url=url, published_year=published_year, tags=tags)
        return str(res)

    @mcp_app.tool()
    def get_library(status_filter: str = "hepsi", query: str = "") -> str:
        """SQLite veritabanındaki kayıtlı makale kütüphanesini ve okuma durumlarını getirir."""
        res = database.get_saved_papers(status_filter=status_filter, query=query)
        return str(res)

    @mcp_app.tool()
    def update_paper_status(paper_id: str, status: str = "", notes: str = "", tags: str = "") -> str:
        """Kayıtlı makalenin okuma durumunu ('unread', 'reading', 'completed') veya notlarını günceller."""
        res = database.update_paper_status_or_note(paper_id=paper_id, status=status, notes=notes, tags=tags)
        return str(res)
    @mcp_app.tool()
    def delete_paper(paper_id: str) -> str:
        """Kütüphaneden bir makaleyi siler."""
        res = database.delete_paper(paper_id=paper_id)
        return str(res)
    
    @mcp_app.tool()
    def clear_library() -> str:
        """Kütüphanedeki TÜM makaleleri veritabanından tamamen siler ve temizler."""
        res = database.clear_library()
        return str(res)
    
    def run_mcp():
        mcp_app.run()

else:
    def run_mcp():
        print("⚠️ MCP kütüphanesi yüklenmedi. Lütfen 'pip install mcp' komutunu çalıştırın.")

if __name__ == "__main__":
    database.init_db()
    run_mcp()