@@ -27,6 +27,7 @@ const (
2727var (
2828searchIndex bleve.Index
2929resources map [string ]mcp.Resource
30+ contents map [string ]mcp.ResourceContents
3031)
3132
3233func RegisterDocsResources (s * server.MCPServer , _ * config.Config ) {
@@ -41,6 +42,7 @@ func RegisterDocsResources(s *server.MCPServer, _ *config.Config) {
4142log .Fatal (fmt .Errorf ("error listing docs files: %w" , err ))
4243}
4344resources = make (map [string ]mcp.Resource , len (docFiles ))
45+ contents = make (map [string ]mcp.ResourceContents , len (docFiles ))
4446for _ , docFile := range docFiles {
4547resourceURI := fmt .Sprintf ("%s%s#%d" , docsURIPrefix , docFile .Path , docFile .ChunkNum )
4648resource := mcp .NewResource (
@@ -52,6 +54,11 @@ func RegisterDocsResources(s *server.MCPServer, _ *config.Config) {
5254s .AddResource (resource , docResourcesHandler )
5355
5456resources [resourceURI ] = resource
57+ contents [resourceURI ] = mcp.TextResourceContents {
58+ URI : resourceURI ,
59+ MIMEType : "text/markdown" ,
60+ Text : docFile .Content ,
61+ }
5562if err = searchIndex .Index (resourceURI , docFile ); err != nil {
5663log .Fatal (fmt .Errorf ("error indexing file %s: %w" , docFile .Path , err ))
5764}
@@ -90,16 +97,12 @@ func docResourcesHandler(_ context.Context, rrr mcp.ReadResourceRequest) ([]mcp.
9097}
9198
9299func GetDocResourceContent (uri string ) (mcp.ResourceContents , error ) {
93- path := strings . TrimPrefix ( uri , docsURIPrefix )
94- content , err := GetDocFileContent ( path )
95- if err != nil {
96- return nil , fmt . Errorf ( "error reading file %s: %w" , path , err )
100+ content , ok := contents [ uri ]
101+ if ! ok {
102+ return nil , fmt . Errorf ( "resource not found: %s" , uri )
103+
97104}
98- return mcp.TextResourceContents {
99- URI : uri ,
100- MIMEType : "text/markdown" ,
101- Text : content ,
102- }, nil
105+ return content , nil
103106}
104107
105108func GetDocFileContent (path string ) (string , error ) {
0 commit comments