-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
102 lines (86 loc) · 2.66 KB
/
server.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from typing import Dict, List
from mcp.server.fastmcp import FastMCP
from minds.client import Client
# Import configuration
from config import (
MINDS_BASE_URL,
FASTMCP_DEBUG,
FASTMCP_LOG_LEVEL,
FASTMCP_HOST,
FASTMCP_PORT,
FASTMCP_SSE_PATH,
FASTMCP_MESSAGE_PATH,
)
# Create the MCP server with customized settings
mcp = FastMCP(
'Minds Enterprise',
debug=FASTMCP_DEBUG,
log_level=FASTMCP_LOG_LEVEL,
host=FASTMCP_HOST,
port=FASTMCP_PORT,
sse_path=FASTMCP_SSE_PATH,
message_path=FASTMCP_MESSAGE_PATH,
)
@mcp.resource('minds://{api_key}', mime_type='application/json')
def get_minds(api_key: str) -> List[Dict]:
'''
Returns a list of available Minds for completion.
Args:
api_key: The Minds API key
Returns:
A list of Mind objects
'''
minds_client = Client(api_key, base_url=MINDS_BASE_URL)
all_minds = minds_client.minds.list()
all_mind_objs = []
for mind in all_minds:
all_mind_objs.append(
{
'name': mind.name,
'model_name': mind.model_name,
'provider': mind.provider,
'parameters': mind.parameters,
'datasources': mind.datasources,
'created_at': mind.created_at,
'updated_at': mind.updated_at,
}
)
return all_mind_objs
@mcp.resource('minds://{mind_name}/{api_key}', mime_type='application/json')
def get_mind(mind_name: str, api_key: str) -> Dict:
'''
Gets a Mind by name.
Args:
mind_name: The name of the Mind to retrieve
api_key: The Minds API key
Returns:
A Mind object
'''
minds_client = Client(api_key, base_url=MINDS_BASE_URL)
mind = minds_client.minds.get(mind_name)
return {
'name': mind.name,
'model_name': mind.model_name,
'provider': mind.provider,
'parameters': mind.parameters,
'datasources': mind.datasources,
'created_at': mind.created_at,
'updated_at': mind.updated_at,
}
@mcp.tool()
def completion(mind_name: str, message: str, api_key: str) -> str:
'''
Generate a completion using the specified Mind.
Args:
mind_name: The ID of the Mind to use for completion
message: The message to complete
api_key: The Minds API key
Returns:
A completion response, either as a string or as a stream of chunks
'''
minds_client = Client(api_key, base_url=MINDS_BASE_URL)
mind = minds_client.minds.get(mind_name)
return mind.completion(message)
if __name__ == '__main__':
# Run the server - FastMCP already has host and port from initialization
mcp.run()