|
| 1 | +# Copyright (c) 2024 Airbyte, Inc., all rights reserved. |
| 2 | +"""MCP prompt definitions for the PyAirbyte MCP server. |
| 3 | +
|
| 4 | +This module defines prompts that can be invoked by MCP clients to perform |
| 5 | +common workflows. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from typing import TYPE_CHECKING, Annotated |
| 11 | + |
| 12 | +from pydantic import Field |
| 13 | + |
| 14 | + |
| 15 | +if TYPE_CHECKING: |
| 16 | + from fastmcp import FastMCP |
| 17 | + |
| 18 | + |
| 19 | +TEST_MY_TOOLS_GUIDANCE = """ |
| 20 | +Test all available tools in this MCP server to confirm they are working properly. |
| 21 | +
|
| 22 | +Guidelines: |
| 23 | +- Iterate through each tool systematically |
| 24 | +- Use read-only operations whenever possible |
| 25 | +- For tools that modify data, use test/safe modes or skip if no safe testing method exists |
| 26 | +- Avoid creating persistent side effects (e.g., don't create real resources, connections, or data) |
| 27 | +- Document which tools were tested and their status |
| 28 | +- Report any errors or issues encountered |
| 29 | +- Provide a summary of the test results at the end |
| 30 | +
|
| 31 | +Focus on validating that tools: |
| 32 | +1. Accept their required parameters correctly |
| 33 | +2. Return expected output formats |
| 34 | +3. Handle errors gracefully |
| 35 | +4. Connect to required services (if applicable) |
| 36 | +
|
| 37 | +Be efficient and practical in your testing approach. |
| 38 | +""".strip() |
| 39 | + |
| 40 | + |
| 41 | +def test_my_tools_prompt( |
| 42 | + scope: Annotated[ |
| 43 | + str | None, |
| 44 | + Field( |
| 45 | + description=( |
| 46 | + "Optional free-form text to focus or constrain testing. " |
| 47 | + "This can be a single word, a sentence, or a paragraph " |
| 48 | + "describing the desired scope or constraints." |
| 49 | + ), |
| 50 | + ), |
| 51 | + ] = None, |
| 52 | +) -> list[dict[str, str]]: |
| 53 | + """Generate a prompt that instructs the agent to test available tools.""" |
| 54 | + content = TEST_MY_TOOLS_GUIDANCE |
| 55 | + |
| 56 | + if scope: |
| 57 | + content = f"{content}\n\n---\n\nAdditional scope or constraints:\n{scope}" |
| 58 | + |
| 59 | + return [ |
| 60 | + { |
| 61 | + "role": "user", |
| 62 | + "content": content, |
| 63 | + } |
| 64 | + ] |
| 65 | + |
| 66 | + |
| 67 | +def register_prompts(app: FastMCP) -> None: |
| 68 | + """Register all prompts with the FastMCP app.""" |
| 69 | + app.prompt( |
| 70 | + name="test-my-tools", |
| 71 | + description="Test all available MCP tools to confirm they are working properly", |
| 72 | + )(test_my_tools_prompt) |
0 commit comments