feat: add package indexing to MCP index_revision tool
The options server's index_revision now also indexes packages when running under nixpkgs-search, matching the CLI behavior. The packages server gets its own index_revision tool for standalone package indexing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -45,7 +45,7 @@ type ServerConfig struct {
|
||||
func DefaultNixOSConfig() ServerConfig {
|
||||
return ServerConfig{
|
||||
Name: "nixos-options",
|
||||
Version: "0.3.0",
|
||||
Version: "0.4.0",
|
||||
DefaultChannel: "nixos-stable",
|
||||
SourceName: "nixpkgs",
|
||||
Mode: ModeOptions,
|
||||
@@ -57,7 +57,9 @@ If the current project contains a flake.lock file, you can index the exact nixpk
|
||||
|
||||
Example: If flake.lock contains "rev": "abc123...", call index_revision with revision "abc123...".
|
||||
|
||||
This ensures option documentation matches the nixpkgs version the project actually uses.`,
|
||||
This ensures option documentation matches the nixpkgs version the project actually uses.
|
||||
|
||||
Note: index_revision also indexes packages when available, so both options and packages become searchable.`,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ This ensures option documentation matches the nixpkgs version the project actual
|
||||
func DefaultNixpkgsPackagesConfig() ServerConfig {
|
||||
return ServerConfig{
|
||||
Name: "nixpkgs-packages",
|
||||
Version: "0.3.0",
|
||||
Version: "0.4.0",
|
||||
DefaultChannel: "nixos-stable",
|
||||
SourceName: "nixpkgs",
|
||||
Mode: ModePackages,
|
||||
@@ -73,7 +75,9 @@ func DefaultNixpkgsPackagesConfig() ServerConfig {
|
||||
|
||||
If the current project contains a flake.lock file, you can search packages from the exact nixpkgs revision used by the project:
|
||||
1. Read the flake.lock file to find the nixpkgs "rev" field
|
||||
2. Ensure the revision is indexed (packages are indexed separately from options)
|
||||
2. Call index_revision with that git hash to index packages for that specific version
|
||||
|
||||
Example: If flake.lock contains "rev": "abc123...", call index_revision with revision "abc123...".
|
||||
|
||||
This ensures package information matches the nixpkgs version the project actually uses.`,
|
||||
}
|
||||
@@ -427,7 +431,7 @@ func (s *Server) getOptionToolDefinitions() []Tool {
|
||||
},
|
||||
{
|
||||
Name: "index_revision",
|
||||
Description: fmt.Sprintf("Index a %s revision to make its options searchable", sourceRepo),
|
||||
Description: s.indexRevisionDescription(sourceRepo),
|
||||
InputSchema: InputSchema{
|
||||
Type: "object",
|
||||
Properties: map[string]Property{
|
||||
@@ -464,6 +468,15 @@ func (s *Server) getOptionToolDefinitions() []Tool {
|
||||
}
|
||||
}
|
||||
|
||||
// indexRevisionDescription returns the description for the index_revision tool,
|
||||
// adjusted based on whether packages are also indexed.
|
||||
func (s *Server) indexRevisionDescription(sourceRepo string) string {
|
||||
if s.config.SourceName == "nixpkgs" {
|
||||
return fmt.Sprintf("Index a %s revision to make its options and packages searchable", sourceRepo)
|
||||
}
|
||||
return fmt.Sprintf("Index a %s revision to make its options searchable", sourceRepo)
|
||||
}
|
||||
|
||||
// getPackageToolDefinitions returns the tool definitions for packages mode.
|
||||
func (s *Server) getPackageToolDefinitions() []Tool {
|
||||
exampleChannels := "'nixos-unstable', 'nixos-24.05'"
|
||||
@@ -547,6 +560,20 @@ func (s *Server) getPackageToolDefinitions() []Tool {
|
||||
Required: []string{"path"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "index_revision",
|
||||
Description: "Index a nixpkgs revision to make its packages searchable",
|
||||
InputSchema: InputSchema{
|
||||
Type: "object",
|
||||
Properties: map[string]Property{
|
||||
"revision": {
|
||||
Type: "string",
|
||||
Description: fmt.Sprintf("Git hash (full or short) or channel name (e.g., %s)", exampleChannels),
|
||||
},
|
||||
},
|
||||
Required: []string{"revision"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "list_revisions",
|
||||
Description: "List all indexed nixpkgs revisions",
|
||||
|
||||
Reference in New Issue
Block a user