Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ef82b54
开源之夏题案 Implement the MCP for Pulsar Admin Tool
Zhianii Jul 5, 2025
67ced57
Update picp-6.md
Zhianii Jul 7, 2025
106c768
项目代码
Zhianii Aug 30, 2025
86f67b3
优化代码细节
Zhianii Aug 30, 2025
a70b730
优化工具指令方法
Zhianii Sep 2, 2025
82d36bd
优化代码
Zhianii Sep 11, 2025
bbddc7e
优化代码
Zhianii Sep 11, 2025
1a4a51f
优化代码
Zhianii Sep 14, 2025
9c54647
优化代码
Zhianii Sep 20, 2025
98be4af
更改部分指令
Zhianii Sep 20, 2025
10038b5
代码优化
Zhianii Sep 21, 2025
2c2e432
代码优化
Zhianii Sep 25, 2025
dc00c02
日志优化
Zhianii Sep 27, 2025
81e4917
日志优化
Zhianii Sep 27, 2025
d93457b
部分代码优化
Zhianii Sep 27, 2025
b7197ac
HTTP连接调整
Zhianii Sep 27, 2025
d3628d9
readme调整
Zhianii Sep 27, 2025
ef38a8e
demo补全
Zhianii Sep 28, 2025
848f010
删除target
Zhianii Oct 13, 2025
30a92dc
修复构建错误
Zhianii Oct 22, 2025
912be92
feat: add core implementation of Pulsar-MCP
Zhianii Aug 30, 2025
d35bb9e
refactor: optimize code details
Zhianii Aug 30, 2025
9042e25
refactor: optimize tool command implementation code
Zhianii Sep 2, 2025
249571e
refactor: optimize code style
Zhianii Sep 11, 2025
bfc9619
refactor: optimize transport management implementation
Zhianii Sep 11, 2025
9d91aaf
refactor: optimize code style
Zhianii Sep 14, 2025
e965513
refactor: optimize code details
Zhianii Sep 20, 2025
3bf9fb2
fix: correct incorrect path
Zhianii Sep 20, 2025
1a66c33
chore: remove unused comments
Zhianii Sep 21, 2025
440b76b
refactor: refine tool command implementation details
Zhianii Sep 25, 2025
a09c407
refactor: optimize code details
Zhianii Sep 27, 2025
33c1f3f
docs: improve README.md
Zhianii Sep 27, 2025
c6857db
refactor: optimize subscription tool command implementation
Zhianii Sep 27, 2025
77a2528
refactor: optimize HTTP connection
Zhianii Sep 27, 2025
ff89f18
docs: improve README.md
Zhianii Sep 27, 2025
1b3fb60
docs: add demo examples
Zhianii Sep 28, 2025
f296490
chore: remove target directory
Zhianii Oct 13, 2025
ee93641
fix: resolve build errors
Zhianii Oct 22, 2025
43d5b85
Merge remote-tracking branch 'origin/pulsar-mcp' into pulsar-mcp
Zhianii Oct 26, 2025
7a26fe3
refactor: optimize code details
Zhianii Oct 26, 2025
e3a042b
Merge remote-tracking branch 'origin/pulsar-mcp' into pulsar-mcp
Zhianii Oct 26, 2025
fc6a561
test: add unit tests for BaseTool and PulsarMCPCliOptions
Zhianii Oct 26, 2025
1d34abe
test: add unit tests for pulsarClient and the transport server
Zhianii Oct 27, 2025
b1225ff
refactor: optimize code details
Zhianii Oct 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions pcip/picp-6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# PCIP-6: Implement the MCP for Pulsar Admin Tool

# Background knowledge

Apache Pulsar is a cloud-native distributed messaging and streaming platform, offering unified messaging, storage, and stream processing. It features multi-tenancy, persistent storage, and seamless scalability. Pulsar provides a command-line tool `pulsar-admin` to manage clusters, tenants, namespaces, topics, and subscriptions. However, `pulsar-admin` requires users to learn a large number of CLI commands and options, which is not user-friendly for non-experts.

Model Context Protocol (MCP) is an open standard that defines how external tools expose capabilities to large language models (LLMs) through structured tool schemas. MCP allows LLMs like GPT or Claude to interact with systems such as Pulsar through well-defined interfaces. This is analogous to USB-C as a standardized interface for hardware devices.

# Motivation

Although `pulsar-admin` provides comprehensive CLI access, it's not user-friendly for non-experts. Users often struggle to express complex management needs, such as "list all subscriptions with message backlog > 1000", using raw CLI syntax.

This proposal aims to introduce a new module that exposes Pulsar Admin functionalities as MCP-compatible tools. This allows users to manage Pulsar clusters using natural language prompts, interpreted and executed by LLMs.

Benefits include:

- Simplified cluster operations using plain English or other natural languages
- Multi-turn conversational interactions with context awareness
- A clean, extensible tool layer that conforms to the `pulsar-java-contrib` architecture


# Goals

## In Scope

- Implement a new module `pulsar-admin-mcp-contrib` to expose Pulsar admin functionalities via MCP protocol.
- Support 70+ commonly used admin operations via structured MCP tools.
- Provide built-in transport support for HTTP, STDIO, and SSE.
- Implement robust context tracking and parameter validation.
- Provide complete developer/user documentation and a demo use case.

## Out of Scope

- UI interfaces or web frontends (though it can be used as backend).
- Pulsar core changes (only builds on `pulsar-java-contrib`).
- Full support for all 120+ CLI commands (70+ are targeted for now).

# High Level Design

The system architecture consists of four main layers:

1. **LLM Interface Layer**: Accepts natural language inputs from an LLM and generates MCP-compatible tool calls
2. **Protocol Layer**: Central MCP interface that dispatches structured requests to tool handlers
3. **Tool Execution Layer**: Looks up registered tools and invokes appropriate Pulsar Admin API operations
4. **Context Management Layer**: Maintains session memory, allowing parameter inheritance across steps

Example interaction:

User input:
> "Create a topic named `user-events` with 3 partitions"

LLMs send structured tool calls (as per MCP schema) such as:
```json
{
"tool": "create-topic",
"parameters": {
"name": "user-events",
"partitions": 3
}
}
```

MCP executes the tool and returns a structured result, which the LLM then summarizes in natural language.
# Detailed Design

## Design & Implementation Details

### Package structure:
```java
pulsar-java-contrib/
├── MCPProtocol.java # MCP protocol interface
├── MCPFactory.java # Factory class for dynamically loading protocol instances
├── tools/ # Tool registration and concrete implementations
├── client/ # PulsarAdmin client management
├── context/ # Session state management
├── validation/ # Parameter validation mechanism
├── transport/ # Support for HTTP, STDIO,SSE
├── model/ # Data structures like ToolSchema, ToolResult, etc
```

### Key components:
- `PulsarAdminTool`: Abstract base class for all tools (e.g. list-topics, create-tenant)
- `ToolExecutor`: Handles concurrency, thread pools, and context updates
- `ToolRegistry`: Registers all tools via Java SPI
- `SessionManager`: Tracks ongoing sessions and enhances parameters
- `ParameterValidator`: Validates tool input against ToolSchema metadata

### Supported tools

**Total tools**: 70+
Grouped by category:
- **Cluster**: list-clusters, create-cluster, get-cluster-stats
- **Tenant**: list-tenants, create-tenant, delete-tenant
- **Namespace**: create-namespace, set-retention-policy, list-namespaces
- **Topic**: create-topic, delete-topic, list-topics, compact-topic, get-topic-stats
- **Subscription**: reset-subscription, get-subscription-stats
- **Message**: produce-message, peek-messages
- **Schema**: upload-schema, check-schema-compatibility
- **Monitoring**: get-cluster-performance, diagnose-topic

Each tool includes:

- A ToolSchema (for LLM prompt templates and validation)
- A handler (e.g. `ListTopicsHandler`)
- Parameter schema, default values, error messages

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<module>pulsar-metrics-contrib</module>
<module>pulsar-auth-contrib</module>
<module>pulsar-rpc-contrib</module>
<module>pulsar-admin-mcp-contrib</module>
</modules>

<dependencyManagement>
Expand Down
Loading