[Python] How to use resources and prompts with FastMcp (python)?

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I use cline to connect my mcpserver.but neither deepseek nor claude couldn't use resources and prompts,only can use tools. I don't find any example on google. Probably now llms unsupported these?

    '''code

    from mcp.server.fastmcp import FastMCP
    mcp = FastMCP("返回今日天气",host='127.0.0.1',port=9000)

    @mcp.tool()
    def get_weather(address:str) -> str:
    """
    查询今日天气
    address:str 要查询的地区
    """
    print("get_weather called")
    if '武汉' in address:
    s = '晴朗,气温26℃'
    else:
    s = '阴天,气温20℃'
    return s
    # 添加动态问候资源
    @mcp.resource("greeting://{name}")
    def get_greeting(name: str) -> str:
    """生成个性化问候语"""
    return f"Hello, {name}!"


    @mcp.prompt()
    def review_code(code: str) -> str:
    return f"Please review this code:\n\n{code}"

    if __name__ == "__main__":
    mcp.run(transport='sse')


    '''

    Continue reading...

Compartilhe esta Página