-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathserver.py
More file actions
79 lines (59 loc) · 2 KB
/
server.py
File metadata and controls
79 lines (59 loc) · 2 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# server.py
from mcp.server.fastmcp import FastMCP
from rag_code import *
# Create an MCP server
mcp = FastMCP("MCP-RAG-app",
host="127.0.0.1",
port=8080,
timeout=30)
@mcp.tool()
def machine_learning_faq_retrieval_tool(query: str) -> str:
"""Retrieve the most relevant documents from the machine learning
FAQ collection. Use this tool when the user asks about ML.
Input:
query: str -> The user query to retrieve the most relevant documents
Output:
context: str -> most relevant documents retrieved from a vector DB
"""
# check type of text
if not isinstance(query, str):
raise ValueError("query must be a string")
retriever = Retriever(QdrantVDB("ml_faq_collection"), EmbedData())
response = retriever.search(query)
return response
@mcp.tool()
def firecrawl_web_search_tool(query: str) -> list[str]:
"""
Search for information on a given topic using Firecrawl.
Use this tool when the user asks about a specific topic or question
that is not related to general machine learning.
Input:
query: str -> The user query to search for information
Output:
context: list[str] -> list of most relevant web search results
"""
# check type of text
if not isinstance(query, str):
raise ValueError("query must be a string")
import requests
import os
from dotenv import load_dotenv
load_dotenv()
url = "https://api.firecrawl.dev/v1/search"
payload = {
"query": query,
"limit": 10,
"lang": "en",
"country": "us",
"timeout": 60000,
"ignoreInvalidURLs": False,
}
headers = {
"Authorization": f"Bearer {os.getenv('FIRECRAWL_API_KEY')}",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
return response.text
if __name__ == "__main__":
print("Starting MCP server at http://127.0.0.1:8080 on port 8080")
mcp.run()