Skip to main content
Glama
KazKozDev
by KazKozDev

Get Element Context

get_context

Retrieve a Markdown element with its surrounding context to understand document structure and relationships between sections.

Instructions

Returns the target element along with its immediate neighbors (before and after).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
pathYesPath to the element (e.g., 'Intro > paragraph 1')

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
afterNoElement after target
beforeNoElement before target
targetNoThe target element

Implementation Reference

  • Core logic that retrieves the target element by path and constructs context with preceding and following sibling elements.
    def get_context(self, path: str) -> Dict[str, Any]:
        """Get element and its neighbors"""
        target = self.find_by_path(path)
        if not target:
            return {"error": "Not found"}
    
        siblings = target.parent.children if target.parent else self.elements
        idx = siblings.index(target)
    
        context = {
            "current": {"path": target.path, "content": target.content},
            "before": None,
            "after": None,
        }
    
        if idx > 0:
            context["before"] = {
                "path": siblings[idx - 1].path,
                "content": siblings[idx - 1].content[:200],
            }
        if idx < len(siblings) - 1:
            context["after"] = {
                "path": siblings[idx + 1].path,
                "content": siblings[idx + 1].content[:200],
            }
    
        return context
  • EditTool instance method that caches/loads the Document and calls its get_context method.
    async def get_context(self, file_path: str, path: str) -> Dict[str, Any]:
        doc = self.get_doc(file_path)
        return doc.get_context(path)
  • Top-level async handler function (get_element_context) imported and called by server.py for the 'get_context' tool.
    async def get_element_context(file_path: str, path: str):
        return await _instance.get_context(file_path, path)
  • JSON schema definition for input (file_path, path) and output (target, before, after objects) of the get_context tool.
    Tool(
        name="get_context",
        title="Get Element Context",
        description="Returns the target element along with its immediate neighbors (before and after).",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {"type": "string", "examples": ["./document.md"]},
                "path": {
                    "type": "string",
                    "description": "Path to the element (e.g., 'Intro > paragraph 1')",
                    "examples": ["Introduction > paragraph 2", "Conclusion"],
                },
            },
            "required": ["file_path", "path"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {
                "target": {"type": "object", "description": "The target element"},
                "before": {
                    "type": "object",
                    "description": "Element before target",
                },
                "after": {"type": "object", "description": "Element after target"},
            },
        },
    ),
  • Registration and dispatch logic in the MCP server's call_tool handler that routes 'get_context' calls to the get_element_context function.
    elif name == "get_context":
        res = await get_element_context(file_path, arguments["path"])
        return CallToolResult(
            content=[TextContent(type="text", text=json.dumps(res, ensure_ascii=False, indent=2))],
            structuredContent=res,
            isError="error" in res,
        )
Behavior2/5

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

With no annotations, the description carries full burden but only states the return content without disclosing behavioral traits like error handling, performance, or side effects. It doesn't mention if it's read-only, safe, or has any limitations beyond the basic functionality.

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 front-loads the core functionality with zero waste. Every word contributes directly to understanding the tool's purpose.

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 the tool has an output schema (which handles return values) and moderate complexity, the description is minimally adequate but lacks depth. It covers the basic operation but misses behavioral context and usage guidelines, leaving gaps in completeness for a tool with no annotations.

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 50% (only 'path' has a description), and the description adds no parameter-specific details beyond what the schema provides. It implies parameters are used to locate the element but doesn't explain their roles or interactions, resulting in a baseline score due to moderate schema coverage.

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 ('Returns') and resource ('target element along with its immediate neighbors'), specifying the scope ('before and after'). It distinguishes from siblings like 'read_element' (which likely returns only the element) and 'get_document_structure' (which likely returns broader structure), though not explicitly named.

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?

No explicit guidance on when to use this tool versus alternatives like 'read_element' or 'get_document_structure' is provided. The description implies usage for contextual analysis but lacks prerequisites, exclusions, or named alternatives.

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/KazKozDev/markdown-editor-mcp-server'

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