- Reorganize tools from single files to logical sub-packages
- Create mixed modular architecture with tools/{module}/{function}.go structure
- Add ToolImpl interface for unified tool registration
- Implement comprehensive tool definitions for all Forgejo operations
- Replace monolithic files with focused modules:
* tools/issue/ - Issue operations (CRUD, comments, labels, attachments, dependencies)
* tools/label/ - Label management
* tools/milestone/ - Milestone management
* tools/release/ - Release management and attachments
* tools/pullreq/ - Pull request operations
* tools/action/ - Forgejo Actions (CI/CD)
* tools/wiki/ - Wiki page management
* tools/repo/ - Repository operations
- Maintain existing functionality while improving code organization
- Enable easier testing and maintenance for individual tool categories
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
//
|
|
// Copyright © 2025 Ronmi Ren <ronmi.ren@gmail.com>
|
|
|
|
package tools
|
|
|
|
import (
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// ToolImpl defines the interface that every tool implementation must satisfy.
|
|
// This interface standardizes how tools are defined and handled, ensuring they
|
|
// can be registered with the MCP server consistently.
|
|
//
|
|
// The generic types In and Out represent the tool's input and output data structures.
|
|
type ToolImpl[In, Out any] interface {
|
|
// Definition returns the formal MCP tool definition, including its name,
|
|
// description, and input schema.
|
|
Definition() *mcp.Tool
|
|
|
|
// Handler returns the function that contains the core logic of the tool.
|
|
// This function is executed when the tool is called by an MCP client.
|
|
Handler() mcp.ToolHandlerFor[In, Out]
|
|
}
|
|
|
|
// Register is a helper function that registers a tool implementation with the MCP server.
|
|
// It retrieves the tool's definition and handler through the ToolImpl interface
|
|
// and adds them to the server's tool registry.
|
|
func Register[I, O any](s *mcp.Server, i ToolImpl[I, O]) {
|
|
mcp.AddTool(s, i.Definition(), i.Handler())
|
|
}
|