Skip to main content
Glama

Educational MCP server to learn BST & AVL trees

A Model Context Protocol (MCP) server designed to help you learn and visualize Binary Search Trees (BST) and AVL Trees. This project implements these data structures in TypeScript, demonstrating core algorithms like insertion, deletion, and AVL rotations.

Features

  • Binary Search Tree (BST): Standard implementation.

  • AVL Tree: Self-balancing binary search tree with automatic rotations (Left, Right, Left-Right, Right-Left).

  • Visualization: Tools to print the tree structure to the console/client to see how it changes after operations.

  • Educational Tools: Explicitly designed to help users "hand trace" or visualize specific tree states.

Related MCP server: GitViz MCP

Installation

  1. Clone the repository.

  2. Install dependencies:

    npm install

Usage

Building the Server

Compile the TypeScript code:

npm run build

Running the Server

Start the MCP server (stdio transport):

npm start

Running Verification Tests

Run the included test script which demonstrates a sequence of insertions and rotations (based on a classic hand-tracing example):

npm test

Using with Claude Desktop

To use this server with the Claude Desktop app, add the following configuration to your claude_desktop_config.json file:

{
  "mcpServers": {
    "bst-avl": {
      "command": "node",
      "args": [
        "/YourDirectory/bst-avl-mcp/build/index.js"
      ]
    }
  }
}

Note: Update the path to match your project location.

Available Tools

  • reset_tree: Resets the specified tree (bst or avl) to be empty.

  • insert_node: Inserts a number into the tree and returns the new visual structure.

  • delete_node: Deletes a number from the tree and maintains balance (for AVL).

  • search_node: Checks if a number exists in the tree.

  • print_tree: Returns a string representation of the current tree hierarchy.

Project Structure

  • src/bst.ts: Basic BST implementation.

  • src/avl.ts: AVL Tree implementation with rotation logic.

  • src/index.ts: MCP Server entry point.

  • src/types.ts: Shared TypeScript interfaces.

Available Tools

5 tools
delete_nodeC

Delete a key from the specified tree.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyYesThe integer key to delete
treeTypeYesThe type of tree to delete from

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations, the description carries the full behavioral burden for a destructive mutation, yet it says nothing about irreversibility, what happens if the key is absent (error vs silent no-op), or whether an AVL tree rebalances after removal. These are exactly the traits an agent needs before calling a delete.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single short sentence with the action front-loaded and no filler. It is efficient, though the terseness contributes to the missing behavioral detail rather than reflecting deliberate economy.

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?

For a two-parameter destructive tool with no annotations and no output schema, the description should at minimum say what is returned or what occurs when the key is not found, and it does not. An agent could invoke it but cannot predict the outcome.

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% and the enum on treeType ('bst'/'avl') is self-documenting, so the schema does the heavy lifting. The description adds no format or constraint detail beyond what is already structured, which is the baseline-3 case.

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?

States a specific verb ('Delete') and resource ('a key from the specified tree'), so the operation is unambiguous. It does not, however, differentiate itself from sibling reset_tree, which also removes data, leaving the agent to infer that this deletes one key rather than clearing the tree.

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 guidance on when to use this versus reset_tree (bulk removal) or on prerequisites such as the key existing in the tree. Usage must be inferred entirely from the name.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

insert_nodeC

Insert a key into the specified tree.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyYesThe integer key to insert
treeTypeYesThe type of tree to insert into

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations, the description carries the full behavioral burden, yet it says nothing about duplicate-key handling, whether the tree is mutated in place, rebalancing for avl, or error behavior. 'Insert' implies mutation but the details an agent needs are absent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single short sentence that is front-loaded with the action and free of filler. It is efficient, though the brevity edges into under-specification rather than optimal density.

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?

For a mutation tool with no annotations and no output schema, the description should at least indicate the effect (tree modified) and any return or duplicate semantics. Given the simple two-parameter schema, that required context is missing.

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 both parameters (key, treeType) are already documented in the schema, including the bst/avl enum. The description adds no syntax, range, or semantics beyond the schema, so the baseline 3 applies.

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?

States a specific verb (insert) plus the resource (a key) and target (tree), which cleanly distinguishes it from delete_node, search_node, print_tree and reset_tree without needing the schema. It does not explicitly name or contrast with siblings, so it stops short of a 5.

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?

There is no statement of when to use this rather than delete_node or search_node, no prerequisites, and no mention of what treeType must already exist. The description offers no usage context at all.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

reset_treeA

Reset the specified tree (bst or avl) to be empty.

ParametersJSON Schema
NameRequiredDescriptionDefault
treeTypeYesThe type of tree to reset

TDQS

A3.7/5.0
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 behavioral burden. It states the resulting state ('to be empty'), which is useful, but doesn't disclose whether this operation is reversible, whether it can fail, or what it returns. Adequate disclosure of the outcome, but not the surrounding behavior.

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?

A single, well-structured sentence with zero waste. The action, target, and resulting state are all front-loaded and unambiguous.

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?

For a simple one-param mutation tool with no annotations or output schema, the description states the core effect but omits behavioral context (permissions, idempotency, error cases). It is minimally complete but leaves the agent without information about anything beyond the resulting state.

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% and the single enum parameter is fully self-documenting in the schema. The description mentions 'bst or avl' but adds no syntactic or format detail beyond the schema, so the baseline of 3 applies.

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?

States a specific verb (reset) and resource (tree), and specifies the target state (empty). Distinguishes itself from siblings like insert_node, delete_node, and search_node, which are all value-level operations rather than wholesale resets.

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?

The usage is implied and clear (reset a whole tree), but the description provides no explicit when-to-use guidance or contrast with alternatives like delete_node, which deletes a single node. No exclusions are stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_nodeC

Search for a key in the specified tree.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyYesThe integer key to search for
treeTypeYesThe type of tree to search in

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full behavioral burden. It doesn't say whether the search mutates the tree, what it returns on a miss, or whether it requires prior insert_node calls. Only the implicit non-destructive nature of 'search' gives any signal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, front-loaded sentence with no wasted words. It is efficiently sized, though it is arguably too terse for the information an agent needs.

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?

With no output schema, the description should explain the return value (found/not found, node or boolean), which it omits entirely. For a lookup tool whose whole value is the result, this is a meaningful gap.

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% — both 'key' (integer to search for) and 'treeType' (enum bst/avl) are documented in the schema. The description adds no format or semantics beyond that, so the baseline of 3 applies.

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?

States a specific verb ('Search') and resource ('a key in the specified tree'), so the agent can tell it apart from insert_node, delete_node, reset_tree and print_tree by action. It does not explicitly name the siblings, but the verb is unambiguous among them.

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?

There is no guidance on when to use this tool versus alternatives, no mention of preconditions (does the tree need to exist?), and no exclusions. Usage is only implied by the verb.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 5 tool updatesv1.0.0
    • First observeddelete_node
    • First observedinsert_node
    • First observedprint_tree
    • First observedreset_tree
    • First observedsearch_node

TDQS

A3.5/5.0

Scored across 5 tools

Disambiguation5/5

Each tool performs a distinct operation on the tree: reset, insert, delete, search, and print. No two tools overlap in purpose, making selection unambiguous.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern (reset_tree, insert_node, delete_node, search_node, print_tree). The convention is predictable and easy to read.

Tool Count5/5

Five tools are well-scoped for a BST/AVL tree server, covering the essential operations without bloat. Each tool clearly earns its place.

Completeness4/5

The surface covers the core lifecycle: reset, insert, delete, search, and visualize. Minor gaps exist for auxiliary queries like tree height, size, or traversal order, but these are not essential for basic tree manipulation.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers