Skip to main content
Glama
james-livefront

Poetry MCP Server

search_poems

Find poems by searching titles, content, and notes with filters for states, forms, and tags to locate specific poetry matching your criteria.

Instructions

Search for poems matching criteria.

Args: query: Text to search for in titles, content, and notes states: Filter by states (e.g., ["completed", "fledgeling"]) forms: Filter by forms (e.g., ["free_verse", "prose_poem"]) tags: Filter by tags (poems must have all specified tags) limit: Maximum number of results to return include_content: Whether to include full poem text in results

Returns: SearchResult with matched poems and query metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
statesNo
formsNo
tagsNo
limitNo
include_contentNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
poemsYesList of poems matching search criteria
query_time_msYesTime taken to execute query in milliseconds
total_matchesYesTotal number of poems matching query (may be > len(poems) if limited)

Implementation Reference

  • The core handler function for the 'search_poems' tool. It performs text search, applies filters for states, forms, and tags, sorts by relevance, limits results, and returns a SearchResult. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def search_poems(
        query: str,
        states: Optional[List[str]] = None,
        forms: Optional[List[str]] = None,
        tags: Optional[List[str]] = None,
        limit: int = 20,
        include_content: bool = False
    ) -> SearchResult:
        """
        Search for poems matching criteria.
    
        Args:
            query: Text to search for in titles, content, and notes
            states: Filter by states (e.g., ["completed", "fledgeling"])
            forms: Filter by forms (e.g., ["free_verse", "prose_poem"])
            tags: Filter by tags (poems must have all specified tags)
            limit: Maximum number of results to return
            include_content: Whether to include full poem text in results
    
        Returns:
            SearchResult with matched poems and query metadata
        """
        import time
        start_time = time.perf_counter()
    
        cat = get_catalog()
    
        # Start with text search if query provided
        if query:
            results = cat.index.search_content(query, case_sensitive=False)
        else:
            # No query, start with all poems
            results = cat.index.all_poems.copy()
    
        # Apply state filter
        if states:
            results = [p for p in results if p.state in states]
    
        # Apply form filter
        if forms:
            results = [p for p in results if p.form in forms]
    
        # Apply tag filter (must have all tags)
        if tags:
            results = [
                p for p in results
                if all(tag.lower() in [t.lower() for t in p.tags] for tag in tags)
            ]
    
        # Sort by relevance (poems with more tag matches first)
        if tags:
            def relevance_score(poem: Poem) -> int:
                return sum(1 for tag in tags if tag.lower() in [t.lower() for t in poem.tags])
            results.sort(key=relevance_score, reverse=True)
    
        # Limit results
        total_matches = len(results)
        results = results[:limit]
    
        # Remove content if not requested
        if not include_content:
            results = [
                Poem(**{**p.model_dump(), 'content': None})
                for p in results
            ]
    
        query_time_ms = (time.perf_counter() - start_time) * 1000
    
        return SearchResult(
            poems=results,
            total_matches=total_matches,
            query_time_ms=query_time_ms
        )
  • Pydantic model defining the output schema for the search_poems tool, including list of poems, total matches, and query time.
    class SearchResult(BaseModel):
        """
        Result from search_poems operation.
    
        Contains matched poems and query metadata.
        """
    
        poems: list[Poem] = Field(
            ...,
            description="List of poems matching search criteria"
        )
    
        total_matches: int = Field(
            ...,
            description="Total number of poems matching query (may be > len(poems) if limited)"
        )
    
        query_time_ms: float = Field(
            ...,
            description="Time taken to execute query in milliseconds"
        )
    
        class Config:
            """Pydantic configuration."""
            json_schema_extra = {
                "example": {
                    "poems": [
                        {
                            "id": "second-bridge",
                            "title": "Second Bridge Out Old Route 12",
                            "state": "completed",
                            "form": "free_verse",
                            "tags": ["water", "memory"]
                        }
                    ],
                    "total_matches": 23,
                    "query_time_ms": 45.2
                }
            }
  • The @mcp.tool() decorator registers the search_poems function as an MCP tool.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions the return type ('SearchResult') but doesn't disclose pagination, rate limits, authentication needs, error conditions, or whether this is a read-only operation. The description is functional but lacks critical operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by well-organized Args and Returns sections. Every sentence adds value—no fluff or repetition. It's appropriately sized for a 6-parameter search tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 6 parameters with 0% schema coverage and no annotations, the description does a decent job explaining parameters and mentions the return type. However, for a search tool with many sibling alternatives and no behavioral annotations, it should provide more guidance on usage context and operational limits to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates well by explaining all 6 parameters with clear semantics: what each filters, examples for states/forms, tag logic ('must have all'), and purpose of include_content. It adds meaningful context beyond the bare schema types, though some details like exact format expectations remain unspecified.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Search for poems matching criteria,' which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'find_poems_by_tag' or 'list_poems_by_state,' which appear to offer more specialized search capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'find_poems_by_tag' or 'list_poems_by_state.' It mentions criteria but doesn't explain trade-offs, prerequisites, or comparative advantages with sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/james-livefront/poetry-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server