Skip to main content
Glama
taylorleese

mcp-toolz

context_search

Search Claude Code contexts using queries, tags, or type filters to find relevant conversations, code snippets, suggestions, or errors.

Instructions

Search Claude Code contexts by query string or tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoSearch query
tagsNoFilter by tags
typeNoFilter by type (conversation, code, suggestion, error)
limitNoMaximum number of results

Implementation Reference

  • The main handler for the 'context_search' tool within the MCP server's call_tool method. It parses input arguments, determines the search mode (tags, query, or list), delegates to storage layer, formats results, and returns as TextContent.
    if name == "context_search":
        query = arguments.get("query")
        tags = arguments.get("tags")
        type_filter = arguments.get("type")
        limit = arguments.get("limit", 10)
    
        # If tags provided, search by tags; otherwise search by query
        if tags:
            contexts = self.storage.get_contexts_by_tags(tags, limit=limit)
        elif query:
            contexts = self.storage.search_contexts(query, type_filter=type_filter, limit=limit)
        else:
            contexts = self.storage.list_contexts(type_filter=type_filter, limit=limit)
    
        result = self._format_contexts_response(contexts)
        return [TextContent(type="text", text=result)]
  • Registration of the 'context_search' tool in the MCP server's list_tools method, including name, description, and detailed input schema.
    Tool(
        name="context_search",
        description="Search Claude Code contexts by query string or tags",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Search query"},
                "tags": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Filter by tags",
                },
                "type": {
                    "type": "string",
                    "description": "Filter by type (conversation, code, suggestion, error)",
                    "enum": ["conversation", "code", "suggestion", "error"],
                },
                "limit": {
                    "type": "integer",
                    "description": "Maximum number of results",
                    "default": 10,
                },
            },
        },
    ),
  • JSON schema defining the input parameters for the context_search tool: query (string), tags (array of strings), type (enum), and limit (integer with default).
    inputSchema={
        "type": "object",
        "properties": {
            "query": {"type": "string", "description": "Search query"},
            "tags": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Filter by tags",
            },
            "type": {
                "type": "string",
                "description": "Filter by type (conversation, code, suggestion, error)",
                "enum": ["conversation", "code", "suggestion", "error"],
            },
            "limit": {
                "type": "integer",
                "description": "Maximum number of results",
                "default": 10,
            },
        },
    },
  • Core search helper method in ContextStorage that performs SQL full-text LIKE searches on title, content, and tags columns, optionally filters by type, orders by timestamp, and limits results.
    def search_contexts(self, query: str, type_filter: str | None = None, limit: int = 10) -> list[ContextEntry]:
        """Search contexts by title, content, or tags."""
        sql_query = """
            SELECT * FROM contexts
            WHERE (
                title LIKE ? OR
                content LIKE ? OR
                tags LIKE ?
            )
        """
        params: list[Any] = [f"%{query}%", f"%{query}%", f"%{query}%"]
    
        if type_filter:
            sql_query += " AND type = ?"
            params.append(type_filter)
    
        sql_query += " ORDER BY timestamp DESC LIMIT ?"
        params.append(limit)
    
        with closing(sqlite3.connect(self.db_path)) as conn:
            conn.row_factory = sqlite3.Row
            cursor = conn.execute(sql_query, params)
            return [self._row_to_context(row) for row in cursor.fetchall()]
  • Helper method for tag-based filtering using dynamic SQL OR conditions on tags column with LIKE wildcards.
    def get_contexts_by_tags(self, tags: list[str], limit: int = 10) -> list[ContextEntry]:
        """Get contexts that match any of the given tags."""
        # Build OR conditions for each tag (using parameterized queries)
        conditions = " OR ".join(["tags LIKE ?"] * len(tags))
        # Safe: only concatenating placeholders, user data goes through params
        query = "SELECT * FROM contexts WHERE " + conditions + " ORDER BY timestamp DESC LIMIT ?"  # nosec B608
        params = [f"%{tag}%" for tag in tags] + [limit]
    
        with closing(sqlite3.connect(self.db_path)) as conn:
            conn.row_factory = sqlite3.Row
            cursor = conn.execute(query, params)
            return [self._row_to_context(row) for row in cursor.fetchall()]
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions searching but doesn't disclose behavioral traits like whether this is a read-only operation, what the return format looks like, if there's pagination, authentication requirements, or rate limits. For a search tool with zero annotation coverage, this is inadequate.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the complexity of a search operation with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'Claude Code contexts' are, what the search returns, or how results are structured. For a tool with this level of complexity and no structured support, more context is needed.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description mentions 'query string or tags' which aligns with two parameters but doesn't add meaning beyond what the schema provides for 'type' or 'limit'. Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('Search') and target resource ('Claude Code contexts'), and specifies search methods ('by query string or tags'). However, it doesn't differentiate from sibling tools like 'context_list' or 'todo_search' which might have overlapping functionality, preventing a perfect score.

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 'context_list' (which might list all contexts without search) or 'todo_search' (which searches todos rather than contexts). There's no mention of prerequisites, typical use cases, or exclusions.

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/taylorleese/mcp-toolz'

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