fast-agent-mcp 0.2.57__py3-none-any.whl → 0.3.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.
Potentially problematic release.
This version of fast-agent-mcp might be problematic. Click here for more details.
- fast_agent/__init__.py +127 -0
- fast_agent/agents/__init__.py +36 -0
- {mcp_agent/core → fast_agent/agents}/agent_types.py +2 -1
- fast_agent/agents/llm_agent.py +217 -0
- fast_agent/agents/llm_decorator.py +486 -0
- mcp_agent/agents/base_agent.py → fast_agent/agents/mcp_agent.py +377 -385
- fast_agent/agents/tool_agent.py +168 -0
- {mcp_agent → fast_agent}/agents/workflow/chain_agent.py +43 -33
- {mcp_agent → fast_agent}/agents/workflow/evaluator_optimizer.py +31 -35
- {mcp_agent → fast_agent}/agents/workflow/iterative_planner.py +56 -47
- {mcp_agent → fast_agent}/agents/workflow/orchestrator_models.py +4 -4
- {mcp_agent → fast_agent}/agents/workflow/parallel_agent.py +34 -41
- {mcp_agent → fast_agent}/agents/workflow/router_agent.py +54 -39
- {mcp_agent → fast_agent}/cli/__main__.py +5 -3
- {mcp_agent → fast_agent}/cli/commands/check_config.py +95 -66
- {mcp_agent → fast_agent}/cli/commands/go.py +20 -11
- {mcp_agent → fast_agent}/cli/commands/quickstart.py +4 -4
- {mcp_agent → fast_agent}/cli/commands/server_helpers.py +1 -1
- {mcp_agent → fast_agent}/cli/commands/setup.py +64 -134
- {mcp_agent → fast_agent}/cli/commands/url_parser.py +9 -8
- {mcp_agent → fast_agent}/cli/main.py +36 -16
- {mcp_agent → fast_agent}/cli/terminal.py +2 -2
- {mcp_agent → fast_agent}/config.py +13 -2
- fast_agent/constants.py +8 -0
- {mcp_agent → fast_agent}/context.py +24 -19
- {mcp_agent → fast_agent}/context_dependent.py +9 -5
- fast_agent/core/__init__.py +17 -0
- {mcp_agent → fast_agent}/core/agent_app.py +39 -36
- fast_agent/core/core_app.py +135 -0
- {mcp_agent → fast_agent}/core/direct_decorators.py +12 -26
- {mcp_agent → fast_agent}/core/direct_factory.py +95 -73
- {mcp_agent → fast_agent/core}/executor/executor.py +4 -5
- {mcp_agent → fast_agent}/core/fastagent.py +32 -32
- fast_agent/core/logging/__init__.py +5 -0
- {mcp_agent → fast_agent/core}/logging/events.py +3 -3
- {mcp_agent → fast_agent/core}/logging/json_serializer.py +1 -1
- {mcp_agent → fast_agent/core}/logging/listeners.py +85 -7
- {mcp_agent → fast_agent/core}/logging/logger.py +7 -7
- {mcp_agent → fast_agent/core}/logging/transport.py +10 -11
- fast_agent/core/prompt.py +9 -0
- {mcp_agent → fast_agent}/core/validation.py +4 -4
- fast_agent/event_progress.py +61 -0
- fast_agent/history/history_exporter.py +44 -0
- {mcp_agent → fast_agent}/human_input/__init__.py +9 -12
- {mcp_agent → fast_agent}/human_input/elicitation_handler.py +26 -8
- {mcp_agent → fast_agent}/human_input/elicitation_state.py +7 -7
- {mcp_agent → fast_agent}/human_input/simple_form.py +6 -4
- {mcp_agent → fast_agent}/human_input/types.py +1 -18
- fast_agent/interfaces.py +228 -0
- fast_agent/llm/__init__.py +9 -0
- mcp_agent/llm/augmented_llm.py → fast_agent/llm/fastagent_llm.py +128 -218
- fast_agent/llm/internal/passthrough.py +137 -0
- mcp_agent/llm/augmented_llm_playback.py → fast_agent/llm/internal/playback.py +29 -25
- mcp_agent/llm/augmented_llm_silent.py → fast_agent/llm/internal/silent.py +10 -17
- fast_agent/llm/internal/slow.py +38 -0
- {mcp_agent → fast_agent}/llm/memory.py +40 -30
- {mcp_agent → fast_agent}/llm/model_database.py +35 -2
- {mcp_agent → fast_agent}/llm/model_factory.py +103 -77
- fast_agent/llm/model_info.py +126 -0
- {mcp_agent/llm/providers → fast_agent/llm/provider/anthropic}/anthropic_utils.py +7 -7
- fast_agent/llm/provider/anthropic/llm_anthropic.py +603 -0
- {mcp_agent/llm/providers → fast_agent/llm/provider/anthropic}/multipart_converter_anthropic.py +79 -86
- fast_agent/llm/provider/bedrock/bedrock_utils.py +218 -0
- fast_agent/llm/provider/bedrock/llm_bedrock.py +2192 -0
- {mcp_agent/llm/providers → fast_agent/llm/provider/google}/google_converter.py +66 -14
- fast_agent/llm/provider/google/llm_google_native.py +431 -0
- mcp_agent/llm/providers/augmented_llm_aliyun.py → fast_agent/llm/provider/openai/llm_aliyun.py +6 -7
- mcp_agent/llm/providers/augmented_llm_azure.py → fast_agent/llm/provider/openai/llm_azure.py +4 -4
- mcp_agent/llm/providers/augmented_llm_deepseek.py → fast_agent/llm/provider/openai/llm_deepseek.py +10 -11
- mcp_agent/llm/providers/augmented_llm_generic.py → fast_agent/llm/provider/openai/llm_generic.py +4 -4
- mcp_agent/llm/providers/augmented_llm_google_oai.py → fast_agent/llm/provider/openai/llm_google_oai.py +4 -4
- mcp_agent/llm/providers/augmented_llm_groq.py → fast_agent/llm/provider/openai/llm_groq.py +14 -16
- mcp_agent/llm/providers/augmented_llm_openai.py → fast_agent/llm/provider/openai/llm_openai.py +133 -206
- mcp_agent/llm/providers/augmented_llm_openrouter.py → fast_agent/llm/provider/openai/llm_openrouter.py +6 -6
- mcp_agent/llm/providers/augmented_llm_tensorzero_openai.py → fast_agent/llm/provider/openai/llm_tensorzero_openai.py +17 -16
- mcp_agent/llm/providers/augmented_llm_xai.py → fast_agent/llm/provider/openai/llm_xai.py +6 -6
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/multipart_converter_openai.py +125 -63
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/openai_multipart.py +12 -12
- {mcp_agent/llm/providers → fast_agent/llm/provider/openai}/openai_utils.py +18 -16
- {mcp_agent → fast_agent}/llm/provider_key_manager.py +2 -2
- {mcp_agent → fast_agent}/llm/provider_types.py +2 -0
- {mcp_agent → fast_agent}/llm/sampling_converter.py +15 -12
- {mcp_agent → fast_agent}/llm/usage_tracking.py +23 -5
- fast_agent/mcp/__init__.py +43 -0
- {mcp_agent → fast_agent}/mcp/elicitation_factory.py +3 -3
- {mcp_agent → fast_agent}/mcp/elicitation_handlers.py +19 -10
- {mcp_agent → fast_agent}/mcp/gen_client.py +3 -3
- fast_agent/mcp/helpers/__init__.py +36 -0
- fast_agent/mcp/helpers/content_helpers.py +183 -0
- {mcp_agent → fast_agent}/mcp/helpers/server_config_helpers.py +8 -8
- {mcp_agent → fast_agent}/mcp/hf_auth.py +25 -23
- fast_agent/mcp/interfaces.py +93 -0
- {mcp_agent → fast_agent}/mcp/logger_textio.py +4 -4
- {mcp_agent → fast_agent}/mcp/mcp_agent_client_session.py +49 -44
- {mcp_agent → fast_agent}/mcp/mcp_aggregator.py +66 -115
- {mcp_agent → fast_agent}/mcp/mcp_connection_manager.py +16 -23
- {mcp_agent/core → fast_agent/mcp}/mcp_content.py +23 -15
- {mcp_agent → fast_agent}/mcp/mime_utils.py +39 -0
- fast_agent/mcp/prompt.py +159 -0
- mcp_agent/mcp/prompt_message_multipart.py → fast_agent/mcp/prompt_message_extended.py +27 -20
- {mcp_agent → fast_agent}/mcp/prompt_render.py +21 -19
- {mcp_agent → fast_agent}/mcp/prompt_serialization.py +46 -46
- fast_agent/mcp/prompts/__main__.py +7 -0
- {mcp_agent → fast_agent}/mcp/prompts/prompt_helpers.py +31 -30
- {mcp_agent → fast_agent}/mcp/prompts/prompt_load.py +8 -8
- {mcp_agent → fast_agent}/mcp/prompts/prompt_server.py +11 -19
- {mcp_agent → fast_agent}/mcp/prompts/prompt_template.py +18 -18
- {mcp_agent → fast_agent}/mcp/resource_utils.py +1 -1
- {mcp_agent → fast_agent}/mcp/sampling.py +31 -26
- {mcp_agent/mcp_server → fast_agent/mcp/server}/__init__.py +1 -1
- {mcp_agent/mcp_server → fast_agent/mcp/server}/agent_server.py +5 -6
- fast_agent/mcp/ui_agent.py +48 -0
- fast_agent/mcp/ui_mixin.py +209 -0
- fast_agent/mcp_server_registry.py +90 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/analysis-campaign.py +5 -4
- {mcp_agent → fast_agent}/resources/examples/data-analysis/analysis.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_forms_server.py +25 -3
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/forms_demo.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/game_character.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/game_character_handler.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/tool_call.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/agent_one.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/agent_two.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher-eval.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher-imp.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/researcher/researcher.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/tensorzero/agent.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/tensorzero/image_demo.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/tensorzero/simple_agent.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/chaining.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/evaluator.py +3 -3
- {mcp_agent → fast_agent}/resources/examples/workflows/human_input.py +5 -3
- {mcp_agent → fast_agent}/resources/examples/workflows/orchestrator.py +1 -1
- {mcp_agent → fast_agent}/resources/examples/workflows/parallel.py +2 -2
- {mcp_agent → fast_agent}/resources/examples/workflows/router.py +5 -2
- fast_agent/resources/setup/.gitignore +24 -0
- fast_agent/resources/setup/agent.py +18 -0
- fast_agent/resources/setup/fastagent.config.yaml +44 -0
- fast_agent/resources/setup/fastagent.secrets.yaml.example +38 -0
- fast_agent/tools/elicitation.py +369 -0
- fast_agent/types/__init__.py +32 -0
- fast_agent/types/llm_stop_reason.py +77 -0
- fast_agent/ui/__init__.py +38 -0
- fast_agent/ui/console_display.py +1005 -0
- {mcp_agent/human_input → fast_agent/ui}/elicitation_form.py +56 -39
- mcp_agent/human_input/elicitation_forms.py → fast_agent/ui/elicitation_style.py +1 -1
- {mcp_agent/core → fast_agent/ui}/enhanced_prompt.py +96 -25
- {mcp_agent/core → fast_agent/ui}/interactive_prompt.py +330 -125
- fast_agent/ui/mcp_ui_utils.py +224 -0
- {mcp_agent → fast_agent/ui}/progress_display.py +2 -2
- {mcp_agent/logging → fast_agent/ui}/rich_progress.py +4 -4
- {mcp_agent/core → fast_agent/ui}/usage_display.py +3 -8
- {fast_agent_mcp-0.2.57.dist-info → fast_agent_mcp-0.3.0.dist-info}/METADATA +7 -7
- fast_agent_mcp-0.3.0.dist-info/RECORD +202 -0
- fast_agent_mcp-0.3.0.dist-info/entry_points.txt +5 -0
- fast_agent_mcp-0.2.57.dist-info/RECORD +0 -192
- fast_agent_mcp-0.2.57.dist-info/entry_points.txt +0 -6
- mcp_agent/__init__.py +0 -114
- mcp_agent/agents/agent.py +0 -92
- mcp_agent/agents/workflow/__init__.py +0 -1
- mcp_agent/agents/workflow/orchestrator_agent.py +0 -597
- mcp_agent/app.py +0 -175
- mcp_agent/core/__init__.py +0 -26
- mcp_agent/core/prompt.py +0 -191
- mcp_agent/event_progress.py +0 -134
- mcp_agent/human_input/handler.py +0 -81
- mcp_agent/llm/__init__.py +0 -2
- mcp_agent/llm/augmented_llm_passthrough.py +0 -232
- mcp_agent/llm/augmented_llm_slow.py +0 -53
- mcp_agent/llm/providers/__init__.py +0 -8
- mcp_agent/llm/providers/augmented_llm_anthropic.py +0 -717
- mcp_agent/llm/providers/augmented_llm_bedrock.py +0 -1788
- mcp_agent/llm/providers/augmented_llm_google_native.py +0 -495
- mcp_agent/llm/providers/sampling_converter_anthropic.py +0 -57
- mcp_agent/llm/providers/sampling_converter_openai.py +0 -26
- mcp_agent/llm/sampling_format_converter.py +0 -37
- mcp_agent/logging/__init__.py +0 -0
- mcp_agent/mcp/__init__.py +0 -50
- mcp_agent/mcp/helpers/__init__.py +0 -25
- mcp_agent/mcp/helpers/content_helpers.py +0 -187
- mcp_agent/mcp/interfaces.py +0 -266
- mcp_agent/mcp/prompts/__init__.py +0 -0
- mcp_agent/mcp/prompts/__main__.py +0 -10
- mcp_agent/mcp_server_registry.py +0 -343
- mcp_agent/tools/tool_definition.py +0 -14
- mcp_agent/ui/console_display.py +0 -790
- mcp_agent/ui/console_display_legacy.py +0 -401
- {mcp_agent → fast_agent}/agents/workflow/orchestrator_prompts.py +0 -0
- {mcp_agent/agents → fast_agent/cli}/__init__.py +0 -0
- {mcp_agent → fast_agent}/cli/constants.py +0 -0
- {mcp_agent → fast_agent}/core/error_handling.py +0 -0
- {mcp_agent → fast_agent}/core/exceptions.py +0 -0
- {mcp_agent/cli → fast_agent/core/executor}/__init__.py +0 -0
- {mcp_agent → fast_agent/core}/executor/task_registry.py +0 -0
- {mcp_agent → fast_agent/core}/executor/workflow_signal.py +0 -0
- {mcp_agent → fast_agent}/human_input/form_fields.py +0 -0
- {mcp_agent → fast_agent}/llm/prompt_utils.py +0 -0
- {mcp_agent/core → fast_agent/llm}/request_params.py +0 -0
- {mcp_agent → fast_agent}/mcp/common.py +0 -0
- {mcp_agent/executor → fast_agent/mcp/prompts}/__init__.py +0 -0
- {mcp_agent → fast_agent}/mcp/prompts/prompt_constants.py +0 -0
- {mcp_agent → fast_agent}/py.typed +0 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/data-analysis/mount-point/WA_Fn-UseC_-HR-Employee-Attrition.csv +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_account_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/elicitation_game_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/elicitations/fastagent.secrets.yaml.example +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/mcp/state-transfer/fastagent.secrets.yaml.example +0 -0
- {mcp_agent → fast_agent}/resources/examples/researcher/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/.env.sample +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/Makefile +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/README.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/clam.jpg +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/crab.png +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/demo_images/shrimp.png +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/docker-compose.yml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/Dockerfile +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/entrypoint.sh +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/mcp_server.py +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/mcp_server/pyproject.toml +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/system_schema.json +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/system_template.minijinja +0 -0
- {mcp_agent → fast_agent}/resources/examples/tensorzero/tensorzero_config/tensorzero.toml +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/fastagent.config.yaml +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/graded_report.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/short_story.md +0 -0
- {mcp_agent → fast_agent}/resources/examples/workflows/short_story.txt +0 -0
- {mcp_agent → fast_agent/ui}/console.py +0 -0
- {mcp_agent/core → fast_agent/ui}/mermaid_utils.py +0 -0
- {fast_agent_mcp-0.2.57.dist-info → fast_agent_mcp-0.3.0.dist-info}/WHEEL +0 -0
- {fast_agent_mcp-0.2.57.dist-info → fast_agent_mcp-0.3.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Utilities for converting between different prompt message formats.
|
|
3
3
|
|
|
4
4
|
This module provides utilities for converting between different serialization formats
|
|
5
|
-
and
|
|
5
|
+
and PromptMessageExtended objects. It includes functionality for:
|
|
6
6
|
|
|
7
7
|
1. JSON Serialization:
|
|
8
|
-
- Converting
|
|
9
|
-
- Parsing GetPromptResult JSON into
|
|
8
|
+
- Converting PromptMessageExtended objects to MCP-compatible GetPromptResult JSON format
|
|
9
|
+
- Parsing GetPromptResult JSON into PromptMessageExtended objects
|
|
10
10
|
- This is ideal for programmatic use and ensures full MCP compatibility
|
|
11
11
|
|
|
12
12
|
2. Delimited Text Format:
|
|
13
|
-
- Converting
|
|
13
|
+
- Converting PromptMessageExtended objects to delimited text (---USER, ---ASSISTANT)
|
|
14
14
|
- Converting resources to JSON after resource delimiter (---RESOURCE)
|
|
15
|
-
- Parsing delimited text back into
|
|
15
|
+
- Parsing delimited text back into PromptMessageExtended objects
|
|
16
16
|
- This maintains human readability for text content while preserving structure for resources
|
|
17
17
|
"""
|
|
18
18
|
|
|
@@ -27,12 +27,12 @@ from mcp.types import (
|
|
|
27
27
|
TextResourceContents,
|
|
28
28
|
)
|
|
29
29
|
|
|
30
|
-
from
|
|
31
|
-
from mcp_agent.mcp.prompts.prompt_constants import (
|
|
30
|
+
from fast_agent.mcp.prompts.prompt_constants import (
|
|
32
31
|
ASSISTANT_DELIMITER,
|
|
33
32
|
RESOURCE_DELIMITER,
|
|
34
33
|
USER_DELIMITER,
|
|
35
34
|
)
|
|
35
|
+
from fast_agent.types import PromptMessageExtended
|
|
36
36
|
|
|
37
37
|
# -------------------------------------------------------------------------
|
|
38
38
|
# JSON Serialization Functions
|
|
@@ -40,13 +40,13 @@ from mcp_agent.mcp.prompts.prompt_constants import (
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
def multipart_messages_to_get_prompt_result(
|
|
43
|
-
messages: List[
|
|
43
|
+
messages: List[PromptMessageExtended],
|
|
44
44
|
) -> GetPromptResult:
|
|
45
45
|
"""
|
|
46
|
-
Convert
|
|
46
|
+
Convert PromptMessageExtended objects to a GetPromptResult container.
|
|
47
47
|
|
|
48
48
|
Args:
|
|
49
|
-
messages: List of
|
|
49
|
+
messages: List of PromptMessageExtended objects
|
|
50
50
|
|
|
51
51
|
Returns:
|
|
52
52
|
GetPromptResult object containing flattened messages
|
|
@@ -60,15 +60,15 @@ def multipart_messages_to_get_prompt_result(
|
|
|
60
60
|
return GetPromptResult(messages=flat_messages)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
def multipart_messages_to_json(messages: List[
|
|
63
|
+
def multipart_messages_to_json(messages: List[PromptMessageExtended]) -> str:
|
|
64
64
|
"""
|
|
65
|
-
Convert
|
|
65
|
+
Convert PromptMessageExtended objects to a pure JSON string in GetPromptResult format.
|
|
66
66
|
|
|
67
67
|
This approach preserves all data and structure exactly as is, compatible with
|
|
68
68
|
the MCP GetPromptResult type.
|
|
69
69
|
|
|
70
70
|
Args:
|
|
71
|
-
messages: List of
|
|
71
|
+
messages: List of PromptMessageExtended objects
|
|
72
72
|
|
|
73
73
|
Returns:
|
|
74
74
|
JSON string representation with GetPromptResult container
|
|
@@ -83,15 +83,15 @@ def multipart_messages_to_json(messages: List[PromptMessageMultipart]) -> str:
|
|
|
83
83
|
return json.dumps(result_dict, indent=2)
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
def
|
|
86
|
+
def json_to_extended_messages(json_str: str) -> List[PromptMessageExtended]:
|
|
87
87
|
"""
|
|
88
|
-
Parse a JSON string in GetPromptResult format into
|
|
88
|
+
Parse a JSON string in GetPromptResult format into PromptMessageExtended objects.
|
|
89
89
|
|
|
90
90
|
Args:
|
|
91
91
|
json_str: JSON string representation of GetPromptResult
|
|
92
92
|
|
|
93
93
|
Returns:
|
|
94
|
-
List of
|
|
94
|
+
List of PromptMessageExtended objects
|
|
95
95
|
"""
|
|
96
96
|
# Parse JSON to dictionary
|
|
97
97
|
result_dict = json.loads(json_str)
|
|
@@ -100,15 +100,15 @@ def json_to_multipart_messages(json_str: str) -> List[PromptMessageMultipart]:
|
|
|
100
100
|
result = GetPromptResult.model_validate(result_dict)
|
|
101
101
|
|
|
102
102
|
# Convert to multipart messages
|
|
103
|
-
return
|
|
103
|
+
return PromptMessageExtended.to_extended(result.messages)
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
def save_messages_to_json_file(messages: List[
|
|
106
|
+
def save_messages_to_json_file(messages: List[PromptMessageExtended], file_path: str) -> None:
|
|
107
107
|
"""
|
|
108
|
-
Save
|
|
108
|
+
Save PromptMessageExtended objects to a JSON file.
|
|
109
109
|
|
|
110
110
|
Args:
|
|
111
|
-
messages: List of
|
|
111
|
+
messages: List of PromptMessageExtended objects
|
|
112
112
|
file_path: Path to save the JSON file
|
|
113
113
|
"""
|
|
114
114
|
json_str = multipart_messages_to_json(messages)
|
|
@@ -117,31 +117,31 @@ def save_messages_to_json_file(messages: List[PromptMessageMultipart], file_path
|
|
|
117
117
|
f.write(json_str)
|
|
118
118
|
|
|
119
119
|
|
|
120
|
-
def load_messages_from_json_file(file_path: str) -> List[
|
|
120
|
+
def load_messages_from_json_file(file_path: str) -> List[PromptMessageExtended]:
|
|
121
121
|
"""
|
|
122
|
-
Load
|
|
122
|
+
Load PromptMessageExtended objects from a JSON file.
|
|
123
123
|
|
|
124
124
|
Args:
|
|
125
125
|
file_path: Path to the JSON file
|
|
126
126
|
|
|
127
127
|
Returns:
|
|
128
|
-
List of
|
|
128
|
+
List of PromptMessageExtended objects
|
|
129
129
|
"""
|
|
130
130
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
131
131
|
json_str = f.read()
|
|
132
132
|
|
|
133
|
-
return
|
|
133
|
+
return json_to_extended_messages(json_str)
|
|
134
134
|
|
|
135
135
|
|
|
136
|
-
def save_messages_to_file(messages: List[
|
|
136
|
+
def save_messages_to_file(messages: List[PromptMessageExtended], file_path: str) -> None:
|
|
137
137
|
"""
|
|
138
|
-
Save
|
|
138
|
+
Save PromptMessageExtended objects to a file, with format determined by file extension.
|
|
139
139
|
|
|
140
140
|
Uses GetPromptResult JSON format for .json files (fully MCP compatible) and
|
|
141
141
|
delimited text format for other extensions.
|
|
142
142
|
|
|
143
143
|
Args:
|
|
144
|
-
messages: List of
|
|
144
|
+
messages: List of PromptMessageExtended objects
|
|
145
145
|
file_path: Path to save the file
|
|
146
146
|
"""
|
|
147
147
|
path_str = str(file_path).lower()
|
|
@@ -154,9 +154,9 @@ def save_messages_to_file(messages: List[PromptMessageMultipart], file_path: str
|
|
|
154
154
|
save_messages_to_delimited_file(messages, file_path)
|
|
155
155
|
|
|
156
156
|
|
|
157
|
-
def load_messages_from_file(file_path: str) -> List[
|
|
157
|
+
def load_messages_from_file(file_path: str) -> List[PromptMessageExtended]:
|
|
158
158
|
"""
|
|
159
|
-
Load
|
|
159
|
+
Load PromptMessageExtended objects from a file, with format determined by file extension.
|
|
160
160
|
|
|
161
161
|
Uses GetPromptResult JSON format for .json files (fully MCP compatible) and
|
|
162
162
|
delimited text format for other extensions.
|
|
@@ -165,7 +165,7 @@ def load_messages_from_file(file_path: str) -> List[PromptMessageMultipart]:
|
|
|
165
165
|
file_path: Path to the file
|
|
166
166
|
|
|
167
167
|
Returns:
|
|
168
|
-
List of
|
|
168
|
+
List of PromptMessageExtended objects
|
|
169
169
|
"""
|
|
170
170
|
path_str = str(file_path).lower()
|
|
171
171
|
|
|
@@ -183,14 +183,14 @@ def load_messages_from_file(file_path: str) -> List[PromptMessageMultipart]:
|
|
|
183
183
|
|
|
184
184
|
|
|
185
185
|
def multipart_messages_to_delimited_format(
|
|
186
|
-
messages: List[
|
|
186
|
+
messages: List[PromptMessageExtended],
|
|
187
187
|
user_delimiter: str = USER_DELIMITER,
|
|
188
188
|
assistant_delimiter: str = ASSISTANT_DELIMITER,
|
|
189
189
|
resource_delimiter: str = RESOURCE_DELIMITER,
|
|
190
190
|
combine_text: bool = True, # Set to False to maintain backward compatibility
|
|
191
191
|
) -> List[str]:
|
|
192
192
|
"""
|
|
193
|
-
Convert
|
|
193
|
+
Convert PromptMessageExtended objects to a hybrid delimited format:
|
|
194
194
|
- Plain text for user/assistant text content with delimiters
|
|
195
195
|
- JSON for resources after resource delimiter
|
|
196
196
|
|
|
@@ -198,7 +198,7 @@ def multipart_messages_to_delimited_format(
|
|
|
198
198
|
preserving structure for resources.
|
|
199
199
|
|
|
200
200
|
Args:
|
|
201
|
-
messages: List of
|
|
201
|
+
messages: List of PromptMessageExtended objects
|
|
202
202
|
user_delimiter: Delimiter for user messages
|
|
203
203
|
assistant_delimiter: Delimiter for assistant messages
|
|
204
204
|
resource_delimiter: Delimiter for resources
|
|
@@ -261,14 +261,14 @@ def multipart_messages_to_delimited_format(
|
|
|
261
261
|
return delimited_content
|
|
262
262
|
|
|
263
263
|
|
|
264
|
-
def
|
|
264
|
+
def delimited_format_to_extended_messages(
|
|
265
265
|
content: str,
|
|
266
266
|
user_delimiter: str = USER_DELIMITER,
|
|
267
267
|
assistant_delimiter: str = ASSISTANT_DELIMITER,
|
|
268
268
|
resource_delimiter: str = RESOURCE_DELIMITER,
|
|
269
|
-
) -> List[
|
|
269
|
+
) -> List[PromptMessageExtended]:
|
|
270
270
|
"""
|
|
271
|
-
Parse hybrid delimited format into
|
|
271
|
+
Parse hybrid delimited format into PromptMessageExtended objects:
|
|
272
272
|
- Plain text for user/assistant text content with delimiters
|
|
273
273
|
- JSON for resources after resource delimiter
|
|
274
274
|
|
|
@@ -279,7 +279,7 @@ def delimited_format_to_multipart_messages(
|
|
|
279
279
|
resource_delimiter: Delimiter for resources
|
|
280
280
|
|
|
281
281
|
Returns:
|
|
282
|
-
List of
|
|
282
|
+
List of PromptMessageExtended objects
|
|
283
283
|
"""
|
|
284
284
|
lines = content.split("\n")
|
|
285
285
|
messages = []
|
|
@@ -324,7 +324,7 @@ def delimited_format_to_multipart_messages(
|
|
|
324
324
|
combined_content.extend(resource_contents)
|
|
325
325
|
|
|
326
326
|
messages.append(
|
|
327
|
-
|
|
327
|
+
PromptMessageExtended(
|
|
328
328
|
role=current_role,
|
|
329
329
|
content=combined_content,
|
|
330
330
|
)
|
|
@@ -427,7 +427,7 @@ def delimited_format_to_multipart_messages(
|
|
|
427
427
|
combined_content.extend(resource_contents)
|
|
428
428
|
|
|
429
429
|
messages.append(
|
|
430
|
-
|
|
430
|
+
PromptMessageExtended(
|
|
431
431
|
role=current_role,
|
|
432
432
|
content=combined_content,
|
|
433
433
|
)
|
|
@@ -437,7 +437,7 @@ def delimited_format_to_multipart_messages(
|
|
|
437
437
|
|
|
438
438
|
|
|
439
439
|
def save_messages_to_delimited_file(
|
|
440
|
-
messages: List[
|
|
440
|
+
messages: List[PromptMessageExtended],
|
|
441
441
|
file_path: str,
|
|
442
442
|
user_delimiter: str = USER_DELIMITER,
|
|
443
443
|
assistant_delimiter: str = ASSISTANT_DELIMITER,
|
|
@@ -445,10 +445,10 @@ def save_messages_to_delimited_file(
|
|
|
445
445
|
combine_text: bool = True,
|
|
446
446
|
) -> None:
|
|
447
447
|
"""
|
|
448
|
-
Save
|
|
448
|
+
Save PromptMessageExtended objects to a file in hybrid delimited format.
|
|
449
449
|
|
|
450
450
|
Args:
|
|
451
|
-
messages: List of
|
|
451
|
+
messages: List of PromptMessageExtended objects
|
|
452
452
|
file_path: Path to save the file
|
|
453
453
|
user_delimiter: Delimiter for user messages
|
|
454
454
|
assistant_delimiter: Delimiter for assistant messages
|
|
@@ -472,9 +472,9 @@ def load_messages_from_delimited_file(
|
|
|
472
472
|
user_delimiter: str = USER_DELIMITER,
|
|
473
473
|
assistant_delimiter: str = ASSISTANT_DELIMITER,
|
|
474
474
|
resource_delimiter: str = RESOURCE_DELIMITER,
|
|
475
|
-
) -> List[
|
|
475
|
+
) -> List[PromptMessageExtended]:
|
|
476
476
|
"""
|
|
477
|
-
Load
|
|
477
|
+
Load PromptMessageExtended objects from a file in hybrid delimited format.
|
|
478
478
|
|
|
479
479
|
Args:
|
|
480
480
|
file_path: Path to the file
|
|
@@ -483,12 +483,12 @@ def load_messages_from_delimited_file(
|
|
|
483
483
|
resource_delimiter: Delimiter for resources
|
|
484
484
|
|
|
485
485
|
Returns:
|
|
486
|
-
List of
|
|
486
|
+
List of PromptMessageExtended objects
|
|
487
487
|
"""
|
|
488
488
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
489
489
|
content = f.read()
|
|
490
490
|
|
|
491
|
-
return
|
|
491
|
+
return delimited_format_to_extended_messages(
|
|
492
492
|
content,
|
|
493
493
|
user_delimiter,
|
|
494
494
|
assistant_delimiter,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Helper functions for working with PromptMessage and
|
|
2
|
+
Helper functions for working with PromptMessage and PromptMessageExtended objects.
|
|
3
3
|
|
|
4
4
|
These utilities simplify extracting content from nested message structures
|
|
5
5
|
without repetitive type checking.
|
|
@@ -13,13 +13,14 @@ from mcp.types import (
|
|
|
13
13
|
TextContent,
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
from
|
|
16
|
+
from fast_agent.mcp.helpers.content_helpers import get_image_data, get_text
|
|
17
17
|
|
|
18
|
-
# Forward reference for
|
|
19
|
-
|
|
18
|
+
# Forward reference for PromptMessageExtended, actual import happens at runtime
|
|
19
|
+
PromptMessageExtendedType = Union[object] # Will be replaced with actual type
|
|
20
20
|
try:
|
|
21
|
-
from
|
|
22
|
-
|
|
21
|
+
from fast_agent.types import PromptMessageExtended
|
|
22
|
+
|
|
23
|
+
PromptMessageExtendedType = PromptMessageExtended
|
|
23
24
|
except ImportError:
|
|
24
25
|
# During initialization, there might be a circular import.
|
|
25
26
|
# We'll handle this gracefully.
|
|
@@ -29,16 +30,16 @@ except ImportError:
|
|
|
29
30
|
class MessageContent:
|
|
30
31
|
"""
|
|
31
32
|
Helper class for working with message content in both PromptMessage and
|
|
32
|
-
|
|
33
|
+
PromptMessageExtended objects.
|
|
33
34
|
"""
|
|
34
35
|
|
|
35
36
|
@staticmethod
|
|
36
|
-
def get_all_text(message: Union[PromptMessage, "
|
|
37
|
+
def get_all_text(message: Union[PromptMessage, "PromptMessageExtended"]) -> List[str]:
|
|
37
38
|
"""
|
|
38
39
|
Extract all text content from a message.
|
|
39
40
|
|
|
40
41
|
Args:
|
|
41
|
-
message: A PromptMessage or
|
|
42
|
+
message: A PromptMessage or PromptMessageExtended
|
|
42
43
|
|
|
43
44
|
Returns:
|
|
44
45
|
List of text strings from all text content parts
|
|
@@ -57,13 +58,13 @@ class MessageContent:
|
|
|
57
58
|
|
|
58
59
|
@staticmethod
|
|
59
60
|
def join_text(
|
|
60
|
-
message: Union[PromptMessage, "
|
|
61
|
+
message: Union[PromptMessage, "PromptMessageExtended"], separator: str = "\n\n"
|
|
61
62
|
) -> str:
|
|
62
63
|
"""
|
|
63
64
|
Join all text content in a message with a separator.
|
|
64
65
|
|
|
65
66
|
Args:
|
|
66
|
-
message: A PromptMessage or
|
|
67
|
+
message: A PromptMessage or PromptMessageExtended
|
|
67
68
|
separator: String to use as separator (default: newlines)
|
|
68
69
|
|
|
69
70
|
Returns:
|
|
@@ -72,12 +73,12 @@ class MessageContent:
|
|
|
72
73
|
return separator.join(MessageContent.get_all_text(message))
|
|
73
74
|
|
|
74
75
|
@staticmethod
|
|
75
|
-
def get_first_text(message: Union[PromptMessage, "
|
|
76
|
+
def get_first_text(message: Union[PromptMessage, "PromptMessageExtended"]) -> Optional[str]:
|
|
76
77
|
"""
|
|
77
78
|
Get the first available text content from a message.
|
|
78
79
|
|
|
79
80
|
Args:
|
|
80
|
-
message: A PromptMessage or
|
|
81
|
+
message: A PromptMessage or PromptMessageExtended
|
|
81
82
|
|
|
82
83
|
Returns:
|
|
83
84
|
First text content or None if no text content exists
|
|
@@ -93,13 +94,13 @@ class MessageContent:
|
|
|
93
94
|
return None
|
|
94
95
|
|
|
95
96
|
@staticmethod
|
|
96
|
-
def has_text_at_first_position(message: Union[PromptMessage, "
|
|
97
|
+
def has_text_at_first_position(message: Union[PromptMessage, "PromptMessageExtended"]) -> bool:
|
|
97
98
|
"""
|
|
98
99
|
Check if a message has a TextContent at the first position.
|
|
99
100
|
This is a common case when dealing with messages that start with text.
|
|
100
101
|
|
|
101
102
|
Args:
|
|
102
|
-
message: A PromptMessage or
|
|
103
|
+
message: A PromptMessage or PromptMessageExtended
|
|
103
104
|
|
|
104
105
|
Returns:
|
|
105
106
|
True if the message has TextContent at first position, False otherwise
|
|
@@ -112,13 +113,13 @@ class MessageContent:
|
|
|
112
113
|
|
|
113
114
|
@staticmethod
|
|
114
115
|
def get_text_at_first_position(
|
|
115
|
-
message: Union[PromptMessage, "
|
|
116
|
+
message: Union[PromptMessage, "PromptMessageExtended"],
|
|
116
117
|
) -> Optional[str]:
|
|
117
118
|
"""
|
|
118
119
|
Get the text from the first position of a message if it's TextContent.
|
|
119
120
|
|
|
120
121
|
Args:
|
|
121
|
-
message: A PromptMessage or
|
|
122
|
+
message: A PromptMessage or PromptMessageExtended
|
|
122
123
|
|
|
123
124
|
Returns:
|
|
124
125
|
The text content at the first position if it's TextContent,
|
|
@@ -134,12 +135,12 @@ class MessageContent:
|
|
|
134
135
|
return cast("TextContent", message.content[0]).text
|
|
135
136
|
|
|
136
137
|
@staticmethod
|
|
137
|
-
def get_all_images(message: Union[PromptMessage, "
|
|
138
|
+
def get_all_images(message: Union[PromptMessage, "PromptMessageExtended"]) -> List[str]:
|
|
138
139
|
"""
|
|
139
140
|
Extract all image data from a message.
|
|
140
141
|
|
|
141
142
|
Args:
|
|
142
|
-
message: A PromptMessage or
|
|
143
|
+
message: A PromptMessage or PromptMessageExtended
|
|
143
144
|
|
|
144
145
|
Returns:
|
|
145
146
|
List of image data strings from all image content parts
|
|
@@ -157,12 +158,12 @@ class MessageContent:
|
|
|
157
158
|
return result
|
|
158
159
|
|
|
159
160
|
@staticmethod
|
|
160
|
-
def get_first_image(message: Union[PromptMessage, "
|
|
161
|
+
def get_first_image(message: Union[PromptMessage, "PromptMessageExtended"]) -> Optional[str]:
|
|
161
162
|
"""
|
|
162
163
|
Get the first available image data from a message.
|
|
163
164
|
|
|
164
165
|
Args:
|
|
165
|
-
message: A PromptMessage or
|
|
166
|
+
message: A PromptMessage or PromptMessageExtended
|
|
166
167
|
|
|
167
168
|
Returns:
|
|
168
169
|
First image data or None if no image content exists
|
|
@@ -179,13 +180,13 @@ class MessageContent:
|
|
|
179
180
|
|
|
180
181
|
@staticmethod
|
|
181
182
|
def get_all_resources(
|
|
182
|
-
message: Union[PromptMessage, "
|
|
183
|
+
message: Union[PromptMessage, "PromptMessageExtended"],
|
|
183
184
|
) -> List[EmbeddedResource]:
|
|
184
185
|
"""
|
|
185
186
|
Extract all embedded resources from a message.
|
|
186
187
|
|
|
187
188
|
Args:
|
|
188
|
-
message: A PromptMessage or
|
|
189
|
+
message: A PromptMessage or PromptMessageExtended
|
|
189
190
|
|
|
190
191
|
Returns:
|
|
191
192
|
List of EmbeddedResource objects
|
|
@@ -198,12 +199,12 @@ class MessageContent:
|
|
|
198
199
|
return [content for content in message.content if isinstance(content, EmbeddedResource)]
|
|
199
200
|
|
|
200
201
|
@staticmethod
|
|
201
|
-
def has_text(message: Union[PromptMessage, "
|
|
202
|
+
def has_text(message: Union[PromptMessage, "PromptMessageExtended"]) -> bool:
|
|
202
203
|
"""
|
|
203
204
|
Check if the message has any text content.
|
|
204
205
|
|
|
205
206
|
Args:
|
|
206
|
-
message: A PromptMessage or
|
|
207
|
+
message: A PromptMessage or PromptMessageExtended
|
|
207
208
|
|
|
208
209
|
Returns:
|
|
209
210
|
True if the message has text content, False otherwise
|
|
@@ -211,12 +212,12 @@ class MessageContent:
|
|
|
211
212
|
return len(MessageContent.get_all_text(message)) > 0
|
|
212
213
|
|
|
213
214
|
@staticmethod
|
|
214
|
-
def has_images(message: Union[PromptMessage, "
|
|
215
|
+
def has_images(message: Union[PromptMessage, "PromptMessageExtended"]) -> bool:
|
|
215
216
|
"""
|
|
216
217
|
Check if the message has any image content.
|
|
217
218
|
|
|
218
219
|
Args:
|
|
219
|
-
message: A PromptMessage or
|
|
220
|
+
message: A PromptMessage or PromptMessageExtended
|
|
220
221
|
|
|
221
222
|
Returns:
|
|
222
223
|
True if the message has image content, False otherwise
|
|
@@ -224,14 +225,14 @@ class MessageContent:
|
|
|
224
225
|
return len(MessageContent.get_all_images(message)) > 0
|
|
225
226
|
|
|
226
227
|
@staticmethod
|
|
227
|
-
def has_resources(message: Union[PromptMessage, "
|
|
228
|
+
def has_resources(message: Union[PromptMessage, "PromptMessageExtended"]) -> bool:
|
|
228
229
|
"""
|
|
229
230
|
Check if the message has any embedded resources.
|
|
230
231
|
|
|
231
232
|
Args:
|
|
232
|
-
message: A PromptMessage or
|
|
233
|
+
message: A PromptMessage or PromptMessageExtended
|
|
233
234
|
|
|
234
235
|
Returns:
|
|
235
236
|
True if the message has embedded resources, False otherwise
|
|
236
237
|
"""
|
|
237
|
-
return len(MessageContent.get_all_resources(message)) > 0
|
|
238
|
+
return len(MessageContent.get_all_resources(message)) > 0
|
|
@@ -8,14 +8,14 @@ from mcp.server.fastmcp.prompts.base import (
|
|
|
8
8
|
)
|
|
9
9
|
from mcp.types import PromptMessage, TextContent
|
|
10
10
|
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
from mcp_agent.mcp.prompts.prompt_template import (
|
|
11
|
+
from fast_agent.core.logging.logger import get_logger
|
|
12
|
+
from fast_agent.mcp import mime_utils, resource_utils
|
|
13
|
+
from fast_agent.mcp.prompts.prompt_template import (
|
|
15
14
|
PromptContent,
|
|
16
15
|
PromptTemplate,
|
|
17
16
|
PromptTemplateLoader,
|
|
18
17
|
)
|
|
18
|
+
from fast_agent.types import PromptMessageExtended
|
|
19
19
|
|
|
20
20
|
# Define message role type
|
|
21
21
|
MessageRole = Literal["user", "assistant"]
|
|
@@ -137,9 +137,9 @@ def load_prompt(file: Path) -> List[PromptMessage]:
|
|
|
137
137
|
return create_messages_with_resources(template.content_sections, [file])
|
|
138
138
|
|
|
139
139
|
|
|
140
|
-
def load_prompt_multipart(file: Path) -> List[
|
|
140
|
+
def load_prompt_multipart(file: Path) -> List[PromptMessageExtended]:
|
|
141
141
|
"""
|
|
142
|
-
Load a prompt from a file and return as
|
|
142
|
+
Load a prompt from a file and return as PromptMessageExtended objects.
|
|
143
143
|
|
|
144
144
|
The loader uses file extension to determine the format:
|
|
145
145
|
- .json files are loaded as MCP SDK compatible GetPromptResult JSON format
|
|
@@ -149,9 +149,9 @@ def load_prompt_multipart(file: Path) -> List[PromptMessageMultipart]:
|
|
|
149
149
|
file: Path to the prompt file
|
|
150
150
|
|
|
151
151
|
Returns:
|
|
152
|
-
List of
|
|
152
|
+
List of PromptMessageExtended objects
|
|
153
153
|
"""
|
|
154
154
|
# First load as regular PromptMessage objects
|
|
155
155
|
messages = load_prompt(file)
|
|
156
156
|
# Then convert to multipart messages
|
|
157
|
-
return
|
|
157
|
+
return PromptMessageExtended.to_extended(messages)
|
|
@@ -23,18 +23,18 @@ from mcp.server.fastmcp.resources import FileResource
|
|
|
23
23
|
from mcp.types import PromptMessage
|
|
24
24
|
from pydantic import AnyUrl
|
|
25
25
|
|
|
26
|
-
from
|
|
27
|
-
from
|
|
26
|
+
from fast_agent.mcp import mime_utils, resource_utils
|
|
27
|
+
from fast_agent.mcp.prompts.prompt_constants import (
|
|
28
28
|
ASSISTANT_DELIMITER as DEFAULT_ASSISTANT_DELIMITER,
|
|
29
29
|
)
|
|
30
|
-
from
|
|
30
|
+
from fast_agent.mcp.prompts.prompt_constants import (
|
|
31
31
|
RESOURCE_DELIMITER as DEFAULT_RESOURCE_DELIMITER,
|
|
32
32
|
)
|
|
33
|
-
from
|
|
33
|
+
from fast_agent.mcp.prompts.prompt_constants import (
|
|
34
34
|
USER_DELIMITER as DEFAULT_USER_DELIMITER,
|
|
35
35
|
)
|
|
36
|
-
from
|
|
37
|
-
from
|
|
36
|
+
from fast_agent.mcp.prompts.prompt_load import create_messages_with_resources
|
|
37
|
+
from fast_agent.mcp.prompts.prompt_template import (
|
|
38
38
|
PromptMetadata,
|
|
39
39
|
PromptTemplateLoader,
|
|
40
40
|
)
|
|
@@ -147,7 +147,7 @@ def register_prompt(file_path: Path, config: Optional[PromptConfig] = None) -> N
|
|
|
147
147
|
# Simple JSON handling - just load and register directly
|
|
148
148
|
from mcp.server.fastmcp.prompts.base import Prompt, PromptArgument
|
|
149
149
|
|
|
150
|
-
from
|
|
150
|
+
from fast_agent.mcp.prompts.prompt_load import load_prompt
|
|
151
151
|
|
|
152
152
|
# Create metadata with minimal information
|
|
153
153
|
metadata = PromptMetadata(
|
|
@@ -229,9 +229,7 @@ def register_prompt(file_path: Path, config: Optional[PromptConfig] = None) -> N
|
|
|
229
229
|
# Create a function with properly typed parameters
|
|
230
230
|
async def template_handler_with_vars(**kwargs):
|
|
231
231
|
# Extract template variables from kwargs
|
|
232
|
-
context = {
|
|
233
|
-
var: kwargs.get(var) for var in template_vars if var in kwargs
|
|
234
|
-
}
|
|
232
|
+
context = {var: kwargs.get(var) for var in template_vars if var in kwargs}
|
|
235
233
|
|
|
236
234
|
# Check for missing variables
|
|
237
235
|
missing_vars = [var for var in template_vars if var not in context]
|
|
@@ -249,9 +247,7 @@ def register_prompt(file_path: Path, config: Optional[PromptConfig] = None) -> N
|
|
|
249
247
|
|
|
250
248
|
# Create a Prompt directly
|
|
251
249
|
arguments = [
|
|
252
|
-
PromptArgument(
|
|
253
|
-
name=var, description=f"Template variable: {var}", required=True
|
|
254
|
-
)
|
|
250
|
+
PromptArgument(name=var, description=f"Template variable: {var}", required=True)
|
|
255
251
|
for var in template_vars
|
|
256
252
|
]
|
|
257
253
|
|
|
@@ -303,9 +299,7 @@ def register_prompt(file_path: Path, config: Optional[PromptConfig] = None) -> N
|
|
|
303
299
|
)
|
|
304
300
|
)
|
|
305
301
|
|
|
306
|
-
logger.info(
|
|
307
|
-
f"Registered resource: {resource_id} ({resource_file})"
|
|
308
|
-
)
|
|
302
|
+
logger.info(f"Registered resource: {resource_id} ({resource_file})")
|
|
309
303
|
except Exception as e:
|
|
310
304
|
logger.error(f"Error registering prompt {file_path}: {e}", exc_info=True)
|
|
311
305
|
|
|
@@ -313,9 +307,7 @@ def register_prompt(file_path: Path, config: Optional[PromptConfig] = None) -> N
|
|
|
313
307
|
def parse_args():
|
|
314
308
|
"""Parse command line arguments"""
|
|
315
309
|
parser = argparse.ArgumentParser(description="FastMCP Prompt Server")
|
|
316
|
-
parser.add_argument(
|
|
317
|
-
"prompt_files", nargs="+", type=str, help="Prompt files to serve"
|
|
318
|
-
)
|
|
310
|
+
parser.add_argument("prompt_files", nargs="+", type=str, help="Prompt files to serve")
|
|
319
311
|
parser.add_argument(
|
|
320
312
|
"--user-delimiter",
|
|
321
313
|
type=str,
|