Skip to main content
Glama
harshil1502

tradingview-mcp

by harshil1502

pine_get_source

Read the current Pine Editor source code from TradingView. The Pine Editor must be open to fetch the script content.

Instructions

Read the current Pine Editor source code. Pine Editor must be open.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for pine_get_source tool. Delegates to page.getPineSource() and wraps errors in ToolExecutionError.
    export async function pineGetSource(
      _input: z.infer<typeof pineGetSourceInput>,
      page: TradingViewPage,
    ): Promise<z.infer<typeof pineGetSourceOutput>> {
      try {
        return await page.getPineSource();
      } catch (cause) {
        throw new ToolExecutionError(
          'pine_get_source',
          'Failed to read Pine source. Is the Pine Editor open?',
          cause,
        );
      }
    }
  • Zod schemas for pine_get_source input (empty) and output (code, scriptName, pineVersion).
    export const pineGetSourceInput = z.object({}).strict();
    export const pineGetSourceOutput = z.object({
      code: z.string(),
      scriptName: z.string().nullable(),
      pineVersion: z.string().nullable(),
    });
  • Registration entry for pine_get_source in the TOOLS registry, linking name, description, schemas, and handler.
    {
      name: 'pine_get_source',
      description:
        'Read the current Pine Editor source code. Pine Editor must be open.',
      input: pineGetSourceInput,
      output: pineGetSourceOutput,
      handler: pineGetSource,
    },
  • Type definition for the PineSource object returned by getPineSource().
    export interface PineSource {
      code: string;
      /** Script name parsed from `//@title <name>` comment, if present. */
      scriptName: string | null;
      /** Pine version parsed from `//@version=<n>` directive, if present. */
      pineVersion: string | null;
    }
  • Helper method on TradingViewPage that uses CDP evaluation to read Pine Editor source from the Monaco editor in TradingView.
    async getPineSource(): Promise<PineSource> {
      const expr = `
        (() => {
          const editor = ${TradingViewPage.LOCATE_PINE_EDITOR_JS};
          if (!editor) return { error: 'Pine Editor not found — is it open?' };
          const code = editor.getValue();
          const titleMatch = code.match(/\\/\\/\\s*@title\\s+(.+)/);
          const versionMatch = code.match(/\\/\\/\\s*@version\\s*=\\s*(\\d+)/);
          return {
            code,
            scriptName: titleMatch ? titleMatch[1].trim() : null,
            pineVersion: versionMatch ? versionMatch[1] : null,
          };
        })()
      `;
      const r = await this.cdp.evaluate<{ error?: string } & PineSource>(expr);
      if (r.error) throw new ChartStateError(r.error);
      return {
        code: r.code,
        scriptName: r.scriptName,
        pineVersion: r.pineVersion,
      };
    }
Behavior3/5

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

No annotations provided; description indicates read-only operation but does not detail behavior if editor is closed or format of returned source code.

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?

Two sentences, front-loaded, no redundant information. Perfectly concise.

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

Completeness4/5

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

For a simple read tool with no parameters, the description covers purpose and precondition. Could mention output format but not essential.

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?

No parameters, description adds no extra parameter info beyond schema. Baseline 4 for 0 parameters.

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?

Clearly states it reads the current Pine Editor source code, distinguishing it from pine_set_source (write) and pine_compile (compile). The verb 'Read' and resource are specific.

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

Usage Guidelines3/5

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

Includes prerequisite 'Pine Editor must be open' but lacks explicit guidance on when to use this tool vs alternatives like pine_compile or saving source code.

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/harshil1502/tradingview-mcp'

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