Skip to main content
Glama
carloshpdoc

memorydetective

Get type info / docs at a Swift source position

swiftGetHoverInfo

Get hover information for Swift source code at a given line and character position, including declaration fragment. Use to check whether a closure's self capture can cause a retain cycle.

Instructions

[mg.code] SourceKit-LSP textDocument/hover at a (line, character) position. Returns the markdown / plaintext hover content plus a best-effort extracted declaration fragment. Use to disambiguate self captures: a class self in a closure can leak; a struct self can't.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to a Swift source file.
lineYesZero-based line number (LSP convention).
characterYesZero-based UTF-16 character offset within the line.
projectRootNo

Implementation Reference

  • Main tool handler: resolves file path, acquires SourceKit-LSP client, calls lspHover, extracts typeName, and returns result.
    export async function swiftGetHoverInfo(
      input: SwiftGetHoverInfoInput,
    ): Promise<SwiftGetHoverInfoResult> {
      const file = resolvePath(input.filePath);
      if (!existsSync(file)) {
        throw new Error(`File not found: ${file}`);
      }
      const root = input.projectRoot
        ? resolvePath(input.projectRoot)
        : projectRootFor(file);
      const client = await acquireClient(root);
      const result = await lspHover(client, file, input.line, input.character);
      const contents = result?.contents ?? "";
      const typeName = extractTypeName(contents);
      return { ok: true, filePath: file, contents, typeName };
    }
  • Zod schema for input validation: filePath (string), line (int), character (int), optional projectRoot.
    export const swiftGetHoverInfoSchema = z.object({
      filePath: z.string().min(1).describe("Absolute path to a Swift source file."),
      line: z
        .number()
        .int()
        .nonnegative()
        .describe("Zero-based line number (LSP convention)."),
      character: z
        .number()
        .int()
        .nonnegative()
        .describe("Zero-based UTF-16 character offset within the line."),
      projectRoot: z.string().optional(),
    });
  • Result type interface: ok, filePath, contents (markdown/plaintext hover), optional typeName (best-effort declaration fragment).
    export interface SwiftGetHoverInfoResult {
      ok: boolean;
      filePath: string;
      /** Markdown / plaintext hover content from SourceKit-LSP. */
      contents: string;
      /** Best-effort extracted declaration fragment (e.g. "class DetailViewModel : ObservableObject"). */
      typeName?: string;
    }
  • src/index.ts:469-481 (registration)
    MCP server registration: tool name 'swiftGetHoverInfo', title, description, inputSchema, and handler that invokes swiftGetHoverInfo.
    server.registerTool(
      "swiftGetHoverInfo",
      {
        title: "Get type info / docs at a Swift source position",
        description:
          "[mg.code] SourceKit-LSP `textDocument/hover` at a (line, character) position. Returns the markdown / plaintext hover content plus a best-effort extracted declaration fragment. Use to disambiguate `self` captures: a class self in a closure can leak; a struct self can't.",
        inputSchema: swiftGetHoverInfoSchema.shape,
      },
      async (input) => {
        const result = await swiftGetHoverInfo(input);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      },
    );
  • Helper function to extract a type/declaration name from hover markdown content using regex.
    function extractTypeName(hover: string): string | undefined {
      // Hover output usually leads with a code fence containing the
      // declaration line (e.g. "let foo: Bar" or "class Baz : Quux").
      const m = hover.match(
        /\b(class|struct|enum|protocol|actor|func|var|let)\s+\S+/,
      );
      return m ? m[0] : undefined;
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It states the tool returns hover content and a declaration fragment, implying a read-only operation. However, it does not explicitly confirm non-destructiveness, mention authentication needs, rate limits, or potential side effects. The description is adequate but could be more explicit about behavioral traits.

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 extremely concise, consisting of two sentences that immediately convey the tool's purpose and a key use case. Every sentence adds value, and there is no fluff or redundant information.

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 absence of an output schema and annotations, the description provides a basic outline of return values but lacks details on error conditions, prerequisites (e.g., project context), or behavior when the source is not part of a project. It is sufficient for simple use but incomplete for complex scenarios.

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

Parameters2/5

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

Schema description coverage is 75%, but the tool description adds no additional meaning beyond what the schema already provides for 'filePath', 'line', and 'character'. The 'projectRoot' parameter lacks a description in both the schema and the tool description, leaving its purpose unclear. The description does not compensate for this gap.

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

Purpose5/5

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

The description clearly states the tool performs a SourceKit-LSP 'textDocument/hover' request at a given source position, specifying the output contains markdown/plaintext hover content and a declaration fragment. It distinguishes itself from sibling tools like swiftFindSymbolReferences and swiftGetSymbolDefinition by focusing on hover info and even provides a specific use case for disambiguating self captures.

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

Usage Guidelines4/5

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

The description explicitly advises when to use this tool: 'Use to disambiguate self captures: a class self in a closure can leak; a struct self can't.' This gives clear context but does not elaborate on when not to use it or mention alternatives beyond the implicit contrast with other 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/carloshpdoc/memorydetective'

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