提示词映射库

mcp_prompt_mapper是一个开源库,用于为Claude、Grok和OpenAI API生成优化的提示词,支持JSON和YAML格式输出,适用于AI开发中的资源与工具构建。

  • by Sumedh1599
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 sumedh1599/mcp_prompt_mapper

使用说明

mcp_prompt_mapper

引言

mcp_prompt_mapper 是一个开源库,旨在为Claude、Grok和OpenAI API生成量身定制的最佳提示。它将输入从 mcp_input_analyzer 转化为结构化、高效的提示,可用于构建MCP服务器的各个部分,包括资源、工具和其他提示。

特性

  • 快速模板:生成用于创建资源和工具的自定义模板。
  • 自定义输出格式:支持针对Claude优化的YAML和JSON格式的输出。
  • 交叉API兼容性:与Claude、Grok和OpenAI API无缝协作。
  • 模式感知自动完成提示:使用自动补全功能确保提示符合架构。
  • 流式输入解析:直接在Claude Desktop中高效解析流式输入。

安装说明

安装 mcp_prompt_mapper你可以使用pip:

pip install mcp_prompt_mapper

或者,如果您更喜欢从源代码安装,请克隆此存储库并运行setup.py:

git clone https://github.com/your-repo/mcp_prompt_mapper.git
cd mcp_prompt_mapper
python setup.py install

使用示例

基础示例

下面是一个如何使用的简单示例 mcp_prompt_mapper 使用默认设置。

from mcp_prompt_mapper import PromptMapper

# Initialize the PromptMapper
prompt_mapper = PromptMapper()

# Sample input from mcp_input_analyzer
input_data = {
    "resource_type": "database",
    "tool_name": "sql_query_tool"
}

# Generate prompts
prompts = prompt_mapper.generate_prompts(input_data)

print(prompts)

自定义输出格式高级示例

此示例演示了如何以YAML格式生成提示。

from mcp_prompt_mapper import PromptMapper

# Initialize the PromptMapper with YAML output format
prompt_mapper = PromptMapper(output_format='yaml')

# Sample input from mcp_input_analyzer
input_data = {
    "resource_type": "api_gateway",
    "tool_name": "http_request_tool"
}

# Generate prompts
prompts = prompt_mapper.generate_prompts(input_data)

print(prompts)

流式输入示例

以下是如何处理Claude Desktop的流式输入。

from mcp_prompt_mapper import PromptMapper

# Initialize the PromptMapper with YAML output format
prompt_mapper = PromptMapper(output_format='yaml')

# Simulate streaming input
streaming_input = [
    {"resource_type": "database", "tool_name": "sql_query_tool"},
    {"resource_type": "api_gateway", "tool_name": "http_request_tool"}
]

for data in streaming_input:
    prompts = prompt_mapper.generate_prompts(data)
    print(prompts)

API文档

类 PromptMapper

  • 初始化

    • __init__(self, output_format='json'):初始化PromptMapper实例。接受可选 output_format 默认为的参数 'json'支持的值包括 'json' 和 'yaml'.
  • 方法 generate_prompts

    • generate_prompts(self, input_data):获取输入数据字典,并根据提供的模式生成提示。以指定的输出格式返回生成的提示。

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。


Ensure you replace `"https://github.com/your-repo/mcp_prompt_mapper.git"` with the actual URL of your repository if it's different. Additionally, ensure that any other paths or references are correctly updated to match your project setup.


## ⚠️ Development Status

This library is currently in early development. Some tests may be failing with the following issues:


Contributions to fix these issues are welcome! Please submit a pull request if you have a solution.