mcp-mesh 0.8.1__py3-none-any.whl → 0.9.0b2__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.
- _mcp_mesh/__init__.py +1 -1
- _mcp_mesh/engine/mesh_llm_agent.py +17 -10
- _mcp_mesh/engine/mesh_llm_agent_injector.py +27 -10
- _mcp_mesh/engine/provider_handlers/__init__.py +2 -0
- _mcp_mesh/engine/provider_handlers/base_provider_handler.py +177 -0
- _mcp_mesh/engine/provider_handlers/claude_handler.py +129 -102
- _mcp_mesh/engine/provider_handlers/gemini_handler.py +218 -48
- _mcp_mesh/engine/provider_handlers/generic_handler.py +31 -0
- _mcp_mesh/engine/provider_handlers/openai_handler.py +4 -1
- _mcp_mesh/pipeline/mcp_heartbeat/rust_heartbeat.py +18 -0
- _mcp_mesh/tracing/trace_context_helper.py +5 -3
- {mcp_mesh-0.8.1.dist-info → mcp_mesh-0.9.0b2.dist-info}/METADATA +2 -2
- {mcp_mesh-0.8.1.dist-info → mcp_mesh-0.9.0b2.dist-info}/RECORD +16 -16
- mesh/helpers.py +39 -46
- {mcp_mesh-0.8.1.dist-info → mcp_mesh-0.9.0b2.dist-info}/WHEEL +0 -0
- {mcp_mesh-0.8.1.dist-info → mcp_mesh-0.9.0b2.dist-info}/licenses/LICENSE +0 -0
mesh/helpers.py
CHANGED
|
@@ -6,7 +6,7 @@ mesh decorators to simplify common patterns like zero-code LLM providers.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
import logging
|
|
9
|
-
from typing import Any,
|
|
9
|
+
from typing import Any, Optional
|
|
10
10
|
|
|
11
11
|
from _mcp_mesh.shared.logging_config import format_log_value
|
|
12
12
|
|
|
@@ -214,62 +214,55 @@ def llm_provider(
|
|
|
214
214
|
f"(requested by consumer)"
|
|
215
215
|
)
|
|
216
216
|
|
|
217
|
+
# Get vendor handler once - used for both structured output and system prompt formatting
|
|
218
|
+
from _mcp_mesh.engine.provider_handlers import ProviderHandlerRegistry
|
|
219
|
+
|
|
220
|
+
handler = ProviderHandlerRegistry.get_handler(vendor)
|
|
221
|
+
|
|
217
222
|
# Issue #459: Handle output_schema for vendor-specific structured output
|
|
218
|
-
#
|
|
223
|
+
# Use provider handler pattern for vendor-specific behavior
|
|
219
224
|
output_schema = model_params_copy.pop("output_schema", None)
|
|
220
225
|
output_type_name = model_params_copy.pop("output_type_name", None)
|
|
221
226
|
|
|
222
|
-
# Vendors that support structured output via response_format
|
|
223
|
-
supported_structured_output_vendors = (
|
|
224
|
-
"openai",
|
|
225
|
-
"azure", # Azure OpenAI uses same format as OpenAI
|
|
226
|
-
"gemini",
|
|
227
|
-
"vertex_ai", # Vertex AI Gemini uses same format as Gemini
|
|
228
|
-
"anthropic",
|
|
229
|
-
)
|
|
230
|
-
|
|
231
227
|
if output_schema:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
228
|
+
# Include messages so handler can modify system prompt (e.g., HINT mode injection)
|
|
229
|
+
model_params_copy["messages"] = request.messages
|
|
230
|
+
handler.apply_structured_output(
|
|
231
|
+
output_schema, output_type_name, model_params_copy
|
|
232
|
+
)
|
|
233
|
+
# Remove messages to avoid duplication in completion_args
|
|
234
|
+
model_params_copy.pop("messages", None)
|
|
235
|
+
logger.debug(
|
|
236
|
+
f"🎯 Applied {vendor} structured output via handler: "
|
|
237
|
+
f"{output_type_name}"
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
# Use vendor handler to format system prompt when tools are present
|
|
241
|
+
messages = request.messages
|
|
242
|
+
if request.tools:
|
|
243
|
+
|
|
244
|
+
# Find and format system message
|
|
245
|
+
formatted_messages = []
|
|
246
|
+
for msg in messages:
|
|
247
|
+
if msg.get("role") == "system":
|
|
248
|
+
# Format system prompt with vendor-specific instructions
|
|
249
|
+
base_prompt = msg.get("content", "")
|
|
250
|
+
formatted_content = handler.format_system_prompt(
|
|
251
|
+
base_prompt=base_prompt,
|
|
252
|
+
tool_schemas=request.tools,
|
|
253
|
+
output_type=str, # Provider returns raw string
|
|
240
254
|
)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
# OpenAI/Azure/Gemini/Vertex: require all properties in 'required', uses strict=True
|
|
244
|
-
schema = make_schema_strict(
|
|
245
|
-
output_schema, add_all_required=True
|
|
255
|
+
formatted_messages.append(
|
|
256
|
+
{"role": "system", "content": formatted_content}
|
|
246
257
|
)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
"type": "json_schema",
|
|
251
|
-
"json_schema": {
|
|
252
|
-
"name": output_type_name or "Response",
|
|
253
|
-
"schema": schema,
|
|
254
|
-
"strict": strict_mode,
|
|
255
|
-
},
|
|
256
|
-
}
|
|
257
|
-
logger.debug(
|
|
258
|
-
f"🎯 Applied {vendor} response_format for structured output: "
|
|
259
|
-
f"{output_type_name} (strict={strict_mode})"
|
|
260
|
-
)
|
|
261
|
-
else:
|
|
262
|
-
# Vendor doesn't support structured output - warn user
|
|
263
|
-
logger.warning(
|
|
264
|
-
f"⚠️ Structured output schema '{output_type_name or 'Response'}' "
|
|
265
|
-
f"was provided but vendor '{vendor}' does not support response_format. "
|
|
266
|
-
f"The schema will be ignored and the LLM may return unstructured output."
|
|
267
|
-
)
|
|
258
|
+
else:
|
|
259
|
+
formatted_messages.append(msg)
|
|
260
|
+
messages = formatted_messages
|
|
268
261
|
|
|
269
262
|
# Build litellm.completion arguments
|
|
270
263
|
completion_args: dict[str, Any] = {
|
|
271
264
|
"model": effective_model,
|
|
272
|
-
"messages":
|
|
265
|
+
"messages": messages,
|
|
273
266
|
**litellm_kwargs,
|
|
274
267
|
}
|
|
275
268
|
|
|
File without changes
|
|
File without changes
|