Skip to content

Conversation

@KKonstantinov
Copy link
Contributor

@KKonstantinov KKonstantinov commented Feb 2, 2026

Refactor RegisteredTool, RegisteredPrompt, RegisteredResource to proper classes

Motivation and Context

The RegisteredTool, RegisteredPrompt, RegisteredResource, and RegisteredResourceTemplate types were previously plain object types. This refactoring converts them to proper classes with:

  • Private fields using # syntax for encapsulation
  • Getter methods for read-only access to properties
  • Simplified update() method using Object.assign for protocol fields
  • Constructor callbacks pattern for communicating with McpServer
  • New getter methods on McpServer to retrieve all registered items
  • Added icons support to RegisteredTool (for parity with protocol Tool type)

How Has This Been Tested?

  • pnpm lint:fix:all - passes
  • pnpm typecheck:all - passes
  • pnpm test:all - 487 tests passing

Breaking Changes

Yes, users will need to update their code:

v1 (update field) v2 (update field) Applies to
paramsSchema inputSchema RegisteredTool.update()
callback handler RegisteredTool.update()

Note: In v1, the RegisteredTool.update() method used paramsSchema which did not match the inputSchema field used in registerTool(). This inconsistency has been fixed in v2 — both now use inputSchema.

New getter methods on McpServer:

  • mcpServer.toolsReadonlyMap<string, RegisteredTool>
  • mcpServer.promptsReadonlyMap<string, RegisteredPrompt>
  • mcpServer.resourcesReadonlyMap<string, RegisteredResource>
  • mcpServer.resourceTemplatesReadonlyMap<string, RegisteredResourceTemplate>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

New file structure

packages/server/src/server/primitives/
├── index.ts          # Re-exports all classes and types
├── types.ts          # Shared callback types (OnUpdate, OnRename, OnRemove)
├── tool.ts           # RegisteredTool class
├── prompt.ts         # RegisteredPrompt class
├── resource.ts       # RegisteredResource class
└── resourceTemplate.ts # RegisteredResourceTemplate class + ResourceTemplate class

Key design decisions

  1. Private fields with #: Uses JavaScript private class fields for true encapsulation
  2. Protocol fields grouped: Protocol-derived fields stored in #protocolFields object, SDK-specific fields stored separately
  3. Simplified update(): Uses Object.assign(this.#protocolFields, protocolUpdates) so new protocol fields automatically work
  4. Constructor callbacks: Classes receive onUpdate, onRename, onRemove callbacks for communicating state changes to McpServer
  5. Type derivation with Omit: Config types derived from protocol types using Omit to automatically include new fields

@KKonstantinov KKonstantinov requested a review from a team as a code owner February 2, 2026 23:50
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1453

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1453

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1453

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1453

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1453

commit: 3dbc7c0

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: 3dbc7c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant