mbxai 1.5.0__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,346 @@
1
+ Metadata-Version: 2.4
2
+ Name: mbxai
3
+ Version: 2.0.0
4
+ Summary: MBX AI SDK
5
+ Project-URL: Homepage, https://www.mibexx.de
6
+ Project-URL: Documentation, https://www.mibexx.de
7
+ Project-URL: Repository, https://github.com/yourusername/mbxai.git
8
+ Author: MBX AI
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.12
16
+ Requires-Dist: fastapi>=0.115.12
17
+ Requires-Dist: httpx>=0.27.0
18
+ Requires-Dist: mcp>=1.7.1
19
+ Requires-Dist: openai>=1.77.0
20
+ Requires-Dist: pydantic-settings>=2.9.1
21
+ Requires-Dist: pydantic>=2.9.1
22
+ Requires-Dist: python-multipart>=0.0.20
23
+ Requires-Dist: sse-starlette>=2.3.4
24
+ Requires-Dist: starlette>=0.46.2
25
+ Requires-Dist: typing-inspection<=0.4.0
26
+ Requires-Dist: uvicorn>=0.34.2
27
+ Provides-Extra: dev
28
+ Requires-Dist: black>=24.3.0; extra == 'dev'
29
+ Requires-Dist: isort>=5.13.2; extra == 'dev'
30
+ Requires-Dist: mypy>=1.8.0; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio>=0.26.0; extra == 'dev'
32
+ Requires-Dist: pytest-cov>=6.1.1; extra == 'dev'
33
+ Requires-Dist: pytest>=8.3.5; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # MBX AI
37
+
38
+ A Python library for building AI applications with LLMs.
39
+
40
+ ## Features
41
+
42
+ - **OpenRouter Integration**: Connect to various LLM providers through OpenRouter
43
+ - **Intelligent Agent System**: AgentClient with dialog-based thinking, question generation, and quality iteration
44
+ - **Tool Integration**: Easily integrate tools with LLMs using the Model Context Protocol (MCP)
45
+ - **Structured Output**: Get structured, typed responses from LLMs
46
+ - **Chat Interface**: Simple chat interface for interacting with LLMs
47
+ - **FastAPI Server**: Built-in FastAPI server for tool integration
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install mbxai
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ### Basic Usage
58
+
59
+ ```python
60
+ from mbxai import OpenRouterClient
61
+
62
+ # Initialize the client
63
+ client = OpenRouterClient(api_key="your-api-key")
64
+
65
+ # Chat with an LLM
66
+ response = await client.chat([
67
+ {"role": "user", "content": "Hello, how are you?"}
68
+ ])
69
+ print(response.choices[0].message.content)
70
+ ```
71
+
72
+ ### Quick Agent Example
73
+
74
+ ```python
75
+ from mbxai import AgentClient, OpenRouterClient
76
+ from pydantic import BaseModel, Field
77
+
78
+ class TravelPlan(BaseModel):
79
+ destination: str = Field(description="Travel destination")
80
+ activities: list[str] = Field(description="Recommended activities")
81
+ budget: str = Field(description="Estimated budget")
82
+
83
+ # Initialize agent
84
+ client = OpenRouterClient(token="your-api-key")
85
+ agent = AgentClient(client)
86
+
87
+ # Get intelligent response with automatic quality improvement
88
+ response = agent.agent(
89
+ prompt="Plan a weekend trip to a mountain destination",
90
+ final_response_structure=TravelPlan,
91
+ ask_questions=False
92
+ )
93
+
94
+ plan = response.final_response
95
+ print(f"Destination: {plan.destination}")
96
+ print(f"Activities: {', '.join(plan.activities)}")
97
+ ```
98
+
99
+ ### Using Tools
100
+
101
+ ```python
102
+ from mbxai import OpenRouterClient, ToolClient
103
+ from pydantic import BaseModel
104
+
105
+ # Define your tool's input and output models
106
+ class CalculatorInput(BaseModel):
107
+ a: float
108
+ b: float
109
+
110
+ class CalculatorOutput(BaseModel):
111
+ result: float
112
+
113
+ # Create a calculator tool
114
+ async def calculator(input: CalculatorInput) -> CalculatorOutput:
115
+ return CalculatorOutput(result=input.a + input.b)
116
+
117
+ # Initialize the client with tools
118
+ client = ToolClient(OpenRouterClient(api_key="your-api-key"))
119
+ client.add_tool(calculator)
120
+
121
+ # Use the tool in a chat
122
+ response = await client.chat([
123
+ {"role": "user", "content": "What is 2 + 3?"}
124
+ ])
125
+ print(response.choices[0].message.content)
126
+ ```
127
+
128
+ ### Using MCP (Model Context Protocol)
129
+
130
+ ```python
131
+ from mbxai import OpenRouterClient, MCPClient
132
+ from mbxai.mcp import MCPServer
133
+ from mcp.server.fastmcp import FastMCP
134
+ from pydantic import BaseModel
135
+
136
+ # Define your tool's input and output models
137
+ class CalculatorInput(BaseModel):
138
+ a: float
139
+ b: float
140
+
141
+ class CalculatorOutput(BaseModel):
142
+ result: float
143
+
144
+ # Create a FastMCP instance
145
+ mcp = FastMCP("calculator-service")
146
+
147
+ # Create a calculator tool
148
+ @mcp.tool()
149
+ async def calculator(argument: CalculatorInput) -> CalculatorOutput:
150
+ return CalculatorOutput(result=argument.a + argument.b)
151
+
152
+ # Start the MCP server
153
+ server = MCPServer("calculator-service")
154
+ await server.add_tool(calculator)
155
+ await server.start()
156
+
157
+ # Initialize the MCP client
158
+ client = MCPClient(OpenRouterClient(api_key="your-api-key"))
159
+ await client.register_mcp_server("calculator-service", "http://localhost:8000")
160
+
161
+ # Use the tool in a chat
162
+ response = await client.chat([
163
+ {"role": "user", "content": "What is 2 + 3?"}
164
+ ])
165
+ print(response.choices[0].message.content)
166
+ ```
167
+
168
+ ### Using AgentClient (Intelligent Dialog System)
169
+
170
+ The `AgentClient` provides an intelligent dialog-based thinking process that can ask clarifying questions, iterate on responses, and provide structured outputs.
171
+
172
+ #### Basic Agent Usage
173
+
174
+ ```python
175
+ from mbxai import AgentClient, OpenRouterClient
176
+ from pydantic import BaseModel, Field
177
+
178
+ # Define your response structure
179
+ class BookRecommendation(BaseModel):
180
+ title: str = Field(description="The title of the recommended book")
181
+ author: str = Field(description="The author of the book")
182
+ genre: str = Field(description="The genre of the book")
183
+ reason: str = Field(description="Why this book is recommended")
184
+
185
+ # Initialize the agent
186
+ client = OpenRouterClient(token="your-api-key")
187
+ agent = AgentClient(client)
188
+
189
+ # Get a recommendation with questions
190
+ response = agent.agent(
191
+ prompt="I want a book recommendation",
192
+ final_response_structure=BookRecommendation,
193
+ ask_questions=True # Agent will ask clarifying questions
194
+ )
195
+
196
+ if response.has_questions():
197
+ # Display questions to user
198
+ for question in response.questions:
199
+ print(f"Q: {question.question}")
200
+
201
+ # Collect answers and continue
202
+ from mbxai import AnswerList, Answer
203
+ answers = AnswerList(answers=[
204
+ Answer(key="genre", answer="I love science fiction"),
205
+ Answer(key="complexity", answer="I prefer complex narratives")
206
+ ])
207
+
208
+ # Continue the conversation
209
+ final_response = agent.answer_to_agent(response.agent_id, answers)
210
+ book_rec = final_response.final_response
211
+ print(f"Recommended: {book_rec.title} by {book_rec.author}")
212
+ else:
213
+ # Direct response without questions
214
+ book_rec = response.final_response
215
+ print(f"Recommended: {book_rec.title} by {book_rec.author}")
216
+ ```
217
+
218
+ #### Agent with Tool Integration
219
+
220
+ ```python
221
+ from mbxai import AgentClient, ToolClient, OpenRouterClient
222
+
223
+ # Initialize with tool support
224
+ openrouter_client = OpenRouterClient(token="your-api-key")
225
+ tool_client = ToolClient(openrouter_client)
226
+ agent = AgentClient(tool_client)
227
+
228
+ # Register tools via the agent (schema auto-generated!)
229
+ def get_weather(location: str, unit: str = "fahrenheit") -> dict:
230
+ """Get weather information for a location.
231
+
232
+ Args:
233
+ location: The city or location name
234
+ unit: Temperature unit (fahrenheit or celsius)
235
+ """
236
+ return {"location": location, "temperature": "72°F", "conditions": "Sunny"}
237
+
238
+ agent.register_tool(
239
+ name="get_weather",
240
+ description="Get current weather for a location",
241
+ function=get_weather
242
+ # Schema automatically generated from function signature!
243
+ )
244
+
245
+ # Use agent with tools
246
+ class WeatherResponse(BaseModel):
247
+ location: str = Field(description="The location")
248
+ weather: str = Field(description="Weather description")
249
+ recommendations: list[str] = Field(description="Clothing recommendations")
250
+
251
+ response = agent.agent(
252
+ prompt="What's the weather in San Francisco and what should I wear?",
253
+ final_response_structure=WeatherResponse,
254
+ ask_questions=False
255
+ )
256
+
257
+ weather_info = response.final_response
258
+ print(f"Weather: {weather_info.weather}")
259
+ ```
260
+
261
+ #### Agent Configuration
262
+
263
+ ```python
264
+ # Configure quality iterations (default: 2)
265
+ agent = AgentClient(
266
+ ai_client=openrouter_client,
267
+ max_iterations=3 # More iterations = higher quality, slower response
268
+ )
269
+
270
+ # Different configurations for different use cases:
271
+ # max_iterations=0: Fastest, basic quality (chatbots)
272
+ # max_iterations=1: Fast, good quality (content generation)
273
+ # max_iterations=2: Balanced (default, recommended)
274
+ # max_iterations=3+: Highest quality (analysis, reports)
275
+ ```
276
+
277
+ #### Agent with MCP Client
278
+
279
+ ```python
280
+ from mbxai import AgentClient, MCPClient
281
+
282
+ # Initialize with MCP support
283
+ mcp_client = MCPClient(OpenRouterClient(token="your-api-key"))
284
+ agent = AgentClient(mcp_client)
285
+
286
+ # Register MCP servers
287
+ agent.register_mcp_server("data-analysis", "http://localhost:8000")
288
+
289
+ # Register individual tools
290
+ agent.register_tool("analyze_data", "Analyze dataset", analyze_function, schema)
291
+
292
+ # Use agent with full MCP capabilities
293
+ response = agent.agent(
294
+ prompt="Analyze the sales data and provide insights",
295
+ final_response_structure=AnalysisReport,
296
+ ask_questions=True
297
+ )
298
+ ```
299
+
300
+ #### Agent Features
301
+
302
+ - **Intelligent Questions**: Automatically generates clarifying questions when needed
303
+ - **Quality Iteration**: Improves responses through multiple AI review cycles
304
+ - **Tool Integration**: Seamlessly works with ToolClient and MCPClient
305
+ - **Structured Output**: Always returns properly typed Pydantic models
306
+ - **Session Management**: Handles multi-turn conversations with question/answer flow
307
+ - **Configurable**: Adjust quality vs speed with max_iterations parameter
308
+
309
+ #### Supported AI Clients
310
+
311
+ | Client | Structured Responses | Tool Registration | MCP Server Registration |
312
+ |--------|---------------------|-------------------|------------------------|
313
+ | OpenRouterClient | ✅ | ❌ | ❌ |
314
+ | ToolClient | ✅ | ✅ | ❌ |
315
+ | MCPClient | ✅ | ✅ | ✅ |
316
+
317
+ ## Development
318
+
319
+ ### Setup
320
+
321
+ 1. Clone the repository:
322
+ ```bash
323
+ git clone https://github.com/yourusername/mbxai.git
324
+ cd mbxai
325
+ ```
326
+
327
+ 2. Create a virtual environment:
328
+ ```bash
329
+ python -m venv .venv
330
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
331
+ ```
332
+
333
+ 3. Install dependencies:
334
+ ```bash
335
+ pip install -e ".[dev]"
336
+ ```
337
+
338
+ ### Running Tests
339
+
340
+ ```bash
341
+ pytest tests/
342
+ ```
343
+
344
+ ## License
345
+
346
+ MIT License
@@ -1,28 +1,37 @@
1
- mbxai/__init__.py,sha256=mTVWACpiOVn0-b8RkDKds5fidOixUuIoeSMF4yk9_ug,47
1
+ mbxai/__init__.py,sha256=EdmX9A6XrdruxZMhQqoULs0JKSsdfWHovjE7LuljcgA,407
2
2
  mbxai/core.py,sha256=WMvmU9TTa7M_m-qWsUew4xH8Ul6xseCZ2iBCXJTW-Bs,196
3
+ mbxai/agent/__init__.py,sha256=5j3mW2NZtAU1s2w8n833axWBQsxW8U0qKwoQ9JtQZ4k,289
4
+ mbxai/agent/client.py,sha256=SORQr0L8qqe9_ffMBrmFKp5ujQBfgPWIfMnGl8X_Qz4,17953
5
+ mbxai/agent/models.py,sha256=oaFBBE_-ufZKUYgjIwbQW4y33BmzXPOnoILzK_vbF24,2147
6
+ mbxai/examples/agent_example.py,sha256=uECWy8QX1IhJMVcdw6EJy6sLcvO8vKgEF_YHJOhZO6Y,5947
7
+ mbxai/examples/agent_iterations_example.py,sha256=xMqZhBWS67EkRkArjOAY2fCgLkQ32Qn9E4CSfEKW4MU,7905
8
+ mbxai/examples/agent_tool_registration_example.py,sha256=oWm0-d4mdba-VQ3HobiCIR0IHtEDCtJenb8Lnm9QqCw,9108
9
+ mbxai/examples/agent_validation_example.py,sha256=xlEf5Mwq5_Iu8bNU4cuHGZVYvAyZNhO2GMFmOom-CLo,4185
10
+ mbxai/examples/auto_schema_example.py,sha256=ymuJJqqDxYznZT2VN6zVFEM7m_lDuccZ1AKSx-xzLTM,8174
3
11
  mbxai/examples/openrouter_example.py,sha256=-grXHKMmFLoh-yUIEMc31n8Gg1S7uSazBWCIOWxgbyQ,1317
4
12
  mbxai/examples/parse_example.py,sha256=eCKMJoOl6qwo8sDP6Trc6ncgjPlgTqi5tPE2kB5_P0k,3821
5
13
  mbxai/examples/parse_tool_example.py,sha256=duHN8scI9ZK6XZ5hdiz1Adzyc-_7tH9Ls9qP4S0bf5s,5477
6
14
  mbxai/examples/request.json,sha256=fjVMses305wVUXgcmjESCvPgP81Js8Kk6zHjZ8EDyEg,5434
7
15
  mbxai/examples/response.json,sha256=4SGJJyQjWWeN__Mrxm6ZtHIo1NUtLEheldd5KaA2mHw,856
8
16
  mbxai/examples/send_request.py,sha256=O5gCHUHy7RvkEFo9IQATgnSOfOdu8OqKHfjAlLDwWPg,6023
17
+ mbxai/examples/simple_agent_test.py,sha256=joCVszUpRkrxHv2DM9QTAh1r6S8iv16pZ-zSPZSBQiU,6391
9
18
  mbxai/examples/tool_client_example.py,sha256=9DNaejXLA85dPbExMiv5y76qlFhzOJF9E5EnMOsy_Dc,3993
10
19
  mbxai/examples/mcp/mcp_client_example.py,sha256=d5-TRHNDdp3nT_NGt0tKpT3VUAJVvqAHSyqkzk9Dd2s,2972
11
20
  mbxai/examples/mcp/mcp_server_example.py,sha256=nFfg22Jnc6HMW_ezLO3So1xwDdx2_rItj5CR-y_Nevs,3966
12
21
  mbxai/mcp/__init__.py,sha256=_ek9iYdYqW5saKetj4qDci11jxesQDiHPJRpHMKkxgU,175
13
22
  mbxai/mcp/client.py,sha256=QRzId6o4_WRWVv3rtm8cfZZGaoY_UlaOO-oqNjY-tmw,5219
14
23
  mbxai/mcp/example.py,sha256=oaol7AvvZnX86JWNz64KvPjab5gg1VjVN3G8eFSzuaE,2350
15
- mbxai/mcp/server.py,sha256=-dzINI4cqzGuGyenXK1Jm9Tq5KS1l59x36Pe0KYgWVc,3332
24
+ mbxai/mcp/server.py,sha256=Qzy8Qg0XfSo2kv2V-lzjhCGvIMbXuEZIRvnc9rNw7LU,3332
16
25
  mbxai/openrouter/__init__.py,sha256=Ito9Qp_B6q-RLGAQcYyTJVWwR2YAZvNqE-HIYXxhtD8,298
17
26
  mbxai/openrouter/client.py,sha256=3LD6WDJ8wjo_nefH5d1NJCsrWPvBc_KBf2NsItUoSt8,18302
18
27
  mbxai/openrouter/config.py,sha256=Ia93s-auim9Sq71eunVDbn9ET5xX2zusXpV4JBdHAzs,3251
19
28
  mbxai/openrouter/models.py,sha256=b3IjjtZAjeGOf2rLsdnCD1HacjTnS8jmv_ZXorc-KJQ,2604
20
29
  mbxai/openrouter/schema.py,sha256=H_77ZrA9zmbX155bWpCJj1jehUyJPS0QybEW1IVAoe0,540
21
30
  mbxai/tools/__init__.py,sha256=ogxrHvgJ7OR62Lmd5x9Eh5d2C0jqWyQis7Zy3yKpZ78,218
22
- mbxai/tools/client.py,sha256=j6yB2hYxvWbaQ5SqN1Fs_YFdPtwettdcMoXcdeV-520,14930
31
+ mbxai/tools/client.py,sha256=2wFPD-UN3Y2DSyrnqxt2vvFgTYHzUl14_y0r6fhAWmM,17198
23
32
  mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
24
- mbxai/tools/types.py,sha256=AIYaX7onY6eRcCEUjrymtiSYFYXi4hpVXLYbj-i9qqo,8277
25
- mbxai-1.5.0.dist-info/METADATA,sha256=d55xUlW3m4tMaz6Fs2dKIWc4TnGcqfuI0jdWe9GkBOY,4147
26
- mbxai-1.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- mbxai-1.5.0.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
28
- mbxai-1.5.0.dist-info/RECORD,,
33
+ mbxai/tools/types.py,sha256=OFfM7scDGTm4FOcJA2ecj-fxL1MEBkqPsT3hqCL1Jto,9505
34
+ mbxai-2.0.0.dist-info/METADATA,sha256=pMQqQnuk1-Jp2QCbM138L7z00P4OGd2DmZB1LEbpXVY,10018
35
+ mbxai-2.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
36
+ mbxai-2.0.0.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
37
+ mbxai-2.0.0.dist-info/RECORD,,
@@ -1,169 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: mbxai
3
- Version: 1.5.0
4
- Summary: MBX AI SDK
5
- Project-URL: Homepage, https://www.mibexx.de
6
- Project-URL: Documentation, https://www.mibexx.de
7
- Project-URL: Repository, https://github.com/yourusername/mbxai.git
8
- Author: MBX AI
9
- License: MIT
10
- License-File: LICENSE
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.12
15
- Requires-Python: >=3.12
16
- Requires-Dist: fastapi>=0.115.12
17
- Requires-Dist: httpx>=0.27.0
18
- Requires-Dist: mcp>=1.7.1
19
- Requires-Dist: openai>=1.77.0
20
- Requires-Dist: pydantic-settings>=2.9.1
21
- Requires-Dist: pydantic>=2.9.1
22
- Requires-Dist: python-multipart>=0.0.20
23
- Requires-Dist: sse-starlette>=2.3.4
24
- Requires-Dist: starlette>=0.46.2
25
- Requires-Dist: typing-inspection<=0.4.0
26
- Requires-Dist: uvicorn>=0.34.2
27
- Provides-Extra: dev
28
- Requires-Dist: black>=24.3.0; extra == 'dev'
29
- Requires-Dist: isort>=5.13.2; extra == 'dev'
30
- Requires-Dist: mypy>=1.8.0; extra == 'dev'
31
- Requires-Dist: pytest-asyncio>=0.26.0; extra == 'dev'
32
- Requires-Dist: pytest-cov>=6.1.1; extra == 'dev'
33
- Requires-Dist: pytest>=8.3.5; extra == 'dev'
34
- Description-Content-Type: text/markdown
35
-
36
- # MBX AI
37
-
38
- A Python library for building AI applications with LLMs.
39
-
40
- ## Features
41
-
42
- - **OpenRouter Integration**: Connect to various LLM providers through OpenRouter
43
- - **Tool Integration**: Easily integrate tools with LLMs using the Model Context Protocol (MCP)
44
- - **Structured Output**: Get structured, typed responses from LLMs
45
- - **Chat Interface**: Simple chat interface for interacting with LLMs
46
- - **FastAPI Server**: Built-in FastAPI server for tool integration
47
-
48
- ## Installation
49
-
50
- ```bash
51
- pip install mbxai
52
- ```
53
-
54
- ## Quick Start
55
-
56
- ### Basic Usage
57
-
58
- ```python
59
- from mbxai import OpenRouterClient
60
-
61
- # Initialize the client
62
- client = OpenRouterClient(api_key="your-api-key")
63
-
64
- # Chat with an LLM
65
- response = await client.chat([
66
- {"role": "user", "content": "Hello, how are you?"}
67
- ])
68
- print(response.choices[0].message.content)
69
- ```
70
-
71
- ### Using Tools
72
-
73
- ```python
74
- from mbxai import OpenRouterClient, ToolClient
75
- from pydantic import BaseModel
76
-
77
- # Define your tool's input and output models
78
- class CalculatorInput(BaseModel):
79
- a: float
80
- b: float
81
-
82
- class CalculatorOutput(BaseModel):
83
- result: float
84
-
85
- # Create a calculator tool
86
- async def calculator(input: CalculatorInput) -> CalculatorOutput:
87
- return CalculatorOutput(result=input.a + input.b)
88
-
89
- # Initialize the client with tools
90
- client = ToolClient(OpenRouterClient(api_key="your-api-key"))
91
- client.add_tool(calculator)
92
-
93
- # Use the tool in a chat
94
- response = await client.chat([
95
- {"role": "user", "content": "What is 2 + 3?"}
96
- ])
97
- print(response.choices[0].message.content)
98
- ```
99
-
100
- ### Using MCP (Model Context Protocol)
101
-
102
- ```python
103
- from mbxai import OpenRouterClient, MCPClient
104
- from mbxai.mcp import MCPServer
105
- from mcp.server.fastmcp import FastMCP
106
- from pydantic import BaseModel
107
-
108
- # Define your tool's input and output models
109
- class CalculatorInput(BaseModel):
110
- a: float
111
- b: float
112
-
113
- class CalculatorOutput(BaseModel):
114
- result: float
115
-
116
- # Create a FastMCP instance
117
- mcp = FastMCP("calculator-service")
118
-
119
- # Create a calculator tool
120
- @mcp.tool()
121
- async def calculator(argument: CalculatorInput) -> CalculatorOutput:
122
- return CalculatorOutput(result=argument.a + argument.b)
123
-
124
- # Start the MCP server
125
- server = MCPServer("calculator-service")
126
- await server.add_tool(calculator)
127
- await server.start()
128
-
129
- # Initialize the MCP client
130
- client = MCPClient(OpenRouterClient(api_key="your-api-key"))
131
- await client.register_mcp_server("calculator-service", "http://localhost:8000")
132
-
133
- # Use the tool in a chat
134
- response = await client.chat([
135
- {"role": "user", "content": "What is 2 + 3?"}
136
- ])
137
- print(response.choices[0].message.content)
138
- ```
139
-
140
- ## Development
141
-
142
- ### Setup
143
-
144
- 1. Clone the repository:
145
- ```bash
146
- git clone https://github.com/yourusername/mbxai.git
147
- cd mbxai
148
- ```
149
-
150
- 2. Create a virtual environment:
151
- ```bash
152
- python -m venv .venv
153
- source .venv/bin/activate # On Windows: .venv\Scripts\activate
154
- ```
155
-
156
- 3. Install dependencies:
157
- ```bash
158
- pip install -e ".[dev]"
159
- ```
160
-
161
- ### Running Tests
162
-
163
- ```bash
164
- pytest tests/
165
- ```
166
-
167
- ## License
168
-
169
- MIT License
File without changes