Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

pinescript-mcp-server

MCP.Pizza Chef: CyberBOB07

The pinescript-mcp-server is a Model Context Protocol server designed to work with TradingView PineScript. It offers automated validation of PineScript code, error fixing for common syntax issues, and generation of validated PineScript templates for strategies and indicators. This server provides a standardized API to integrate PineScript code management into AI workflows, enabling seamless code quality assurance and generation.

Use This MCP server To

Validate PineScript code for syntax errors and warnings automatically Automatically fix common PineScript syntax errors in code Generate validated PineScript templates for trading strategies Generate validated PineScript templates for technical indicators Integrate PineScript validation and generation into AI-assisted trading tools Streamline PineScript code review and correction workflows Enable real-time PineScript code quality checks in development environments

README

TradingView PineScript MCP Server

A Model Context Protocol (MCP) server for working with TradingView PineScript. This server provides tools for validating, fixing, and generating PineScript code through a standardized API.

Features

  • PineScript Validation - Automatically validates PineScript code for syntax errors and warnings
  • Error Fixing - Automatically fixes common PineScript syntax errors
  • Template Generation - Provides validated templates for various PineScript strategies and indicators

Getting Started

Prerequisites

  • Node.js 16.x or higher
  • npm 8.x or higher

Installation

  1. Clone the repository
git clone https://github.com/yourusername/pinescriptproject1.git
cd pinescriptproject1
  1. Install dependencies
npm install
  1. Build the project
npm run build

Running the Server

Start the MCP server:

npm run start-server

This will start the server with stdio transport, which allows it to communicate with MCP clients.

API

Tools

The MCP server exposes the following tools:

1. validate_pinescript

Validates PineScript code for syntax errors and warnings.

Parameters:

  • script (string): The PineScript code to validate
  • version (string, optional): Expected PineScript version (e.g., 'v5', 'v4')

Returns:

  • valid (boolean): Whether the script is valid
  • errors (string[]): List of syntax errors
  • warnings (string[]): List of warnings
2. fix_pinescript_errors

Automatically fixes common syntax errors in PineScript code.

Parameters:

  • script (string): The PineScript code to fix

Returns:

  • fixed (boolean): Whether any fixes were applied
  • fixedCode (string): The fixed script
  • changes (string[]): List of changes made
3. get_pinescript_template

Provides validated templates for common PineScript strategies and indicators.

Parameters:

  • template_type (string): Type of template ('strategy' or 'indicator')
  • name (string): Template name

Returns:

  • template (string): The template code
  • message (string): Confirmation message

Supported PineScript Features

Syntax Validation

The validator currently checks for:

  • Empty scripts
  • Version annotations
  • Balanced parentheses
  • String quotes
  • Comma placement in function calls
  • Deprecated functions in PineScript v5
  • Incorrect variable export syntax

Error Fixing

The fixer can automatically fix:

  • Missing version annotations
  • Unbalanced parentheses
  • Unclosed string literals
  • Missing commas in function calls
  • Deprecated study() function
  • Incorrect variable export syntax

Development

Running Tests

npm test

Debugging

To run the server in development mode with automatic reloading:

npm run dev

License

ISC

Contributing

Contributions are welcome!

pinescript-mcp-server FAQ

How do I install the pinescript-mcp-server?
Clone the repository, install dependencies with npm, build the project, and start the server using npm scripts.
What prerequisites are needed to run this MCP server?
Node.js 16.x or higher and npm 8.x or higher are required.
Can this server automatically fix PineScript code errors?
Yes, it can automatically fix common syntax errors in PineScript code.
Does the server support generating PineScript templates?
Yes, it provides validated templates for various PineScript strategies and indicators.
How does this MCP server communicate with clients?
It uses stdio transport for communication, enabling integration with MCP clients.
Is this server limited to a specific PineScript version?
The server is designed to work with TradingView PineScript, typically supporting the latest stable versions.
Can this MCP server be integrated into AI workflows?
Yes, it exposes a standardized API suitable for AI-assisted PineScript code validation and generation.
What benefits does this server provide over manual PineScript coding?
It automates error detection, correction, and template generation, reducing manual effort and improving code quality.