mcp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcp exposes a vault to AI agents over the Model Context Protocol. Service holds the tool logic as plain Go methods; NewServer registers them with the official SDK. The server does not know about its transport: `nota mcp` serves it over stdio, and `nota serve` can hand the same *sdk.Server to the SDK's streamable HTTP handler.

Index

Constants

View Source
const URIPrefix = "nota://note/"

URIPrefix starts the URI of every note resource: nota://note/<path>, with the vault path percent-encoded segment by segment.

View Source
const URITemplate = "nota://note/{+path}"

URITemplate is the resource template of notes. {+path} keeps the slashes of folder paths readable; percent-encoded paths work too.

Variables

View Source
var (
	ErrAmbiguous = errors.New("ambiguous note reference")
	ErrConflict  = errors.New("note changed since it was read")
)

Errors the tools return. They reach the client as tool errors.

Functions

func Hash

func Hash(raw []byte) string

Hash is the content hash used for optimistic updates.

func NewServer

func NewServer(s *Service, version string, logger *slog.Logger) *sdk.Server

NewServer returns an MCP server with the vault tools and the note resources. Serve it on any transport, e.g. server.Run(ctx, &sdk.StdioTransport{}).

func PathFromURI

func PathFromURI(uri string) (string, error)

PathFromURI returns the vault path of a note resource URI.

func URI

func URI(p string) string

URI returns the resource URI of a vault path.

Types

type AppendInput

type AppendInput struct {
	Note string `json:"note" jsonschema:"the note: a path, title, unique prefix or nota://note/ URI"`
	Text string `json:"text" jsonschema:"markdown to add at the end, on a line of its own; start with an empty line for a new paragraph"`
}

AppendInput are the arguments of append_to_note.

type BacklinksOutput

type BacklinksOutput struct {
	Note      string       `json:"note"`
	Backlinks []index.Link `json:"backlinks"`
}

BacklinksOutput is the result of get_backlinks.

type CreateInput

type CreateInput struct {
	Title      string         `` /* 147-byte string literal not displayed */
	Body       string         `json:"body,omitempty" jsonschema:"markdown content"`
	Folder     string         `json:"folder,omitempty" jsonschema:"folder for the note; default the inbox, '/' for the vault root"`
	Tags       []string       `json:"tags,omitempty" jsonschema:"tags for the frontmatter, without #"`
	Properties map[string]any `json:"properties,omitempty" jsonschema:"extra frontmatter keys"`
}

CreateInput are the arguments of create_note.

type FrontmatterInput

type FrontmatterInput struct {
	Note  string         `json:"note" jsonschema:"the note: a path, title, unique prefix or nota://note/ URI"`
	Set   map[string]any `json:"set,omitempty" jsonschema:"keys to set, with JSON values (strings, numbers, booleans, lists, objects)"`
	Unset []string       `json:"unset,omitempty" jsonschema:"keys to remove"`
}

FrontmatterInput are the arguments of update_frontmatter.

type ListInput

type ListInput struct {
	Folder string   `json:"folder,omitempty" jsonschema:"only notes in this folder and its subfolders"`
	Tag    string   `json:"tag,omitempty" jsonschema:"only notes with this tag (nested tags included)"`
	Where  []string `json:"where,omitempty" jsonschema:"frontmatter conditions, each key=value or key!=value (case-insensitive; list items match)"`
	View   string   `json:"view,omitempty" jsonschema:"start from a saved view (see list_views); the other filters narrow it"`
	Sort   string   `json:"sort,omitempty" jsonschema:"path, title, created, updated or modified, optionally followed by asc or desc"`
	Limit  int      `json:"limit,omitempty" jsonschema:"maximum number of notes (default 100)"`
}

ListInput are the arguments of list_notes.

type MoveInput

type MoveInput struct {
	Note   string `json:"note" jsonschema:"the note: a path, title, unique prefix or nota://note/ URI"`
	Folder string `json:"folder" jsonschema:"target folder, created when missing; '/' for the vault root"`
}

MoveInput are the arguments of move_note.

type MoveOutput

type MoveOutput struct {
	From string `json:"from"`
	Path string `json:"path"`
	URI  string `json:"uri"`
}

MoveOutput is the result of move_note.

type Note

type Note struct {
	NoteInfo
	Body    string `json:"body" jsonschema:"the markdown after the frontmatter"`
	Content string `json:"content" jsonschema:"the whole file"`
	Hash    string `json:"hash" jsonschema:"hash of the file; pass it to update_note as expected_hash"`
}

Note is a note with its content.

type NoteInfo

type NoteInfo struct {
	Path       string         `json:"path" jsonschema:"vault-relative path, the note's identity"`
	URI        string         `json:"uri" jsonschema:"resource URI of the note"`
	Folder     string         `json:"folder" jsonschema:"folder of the note, empty for the vault root"`
	Title      string         `json:"title"`
	Tags       []string       `json:"tags" jsonschema:"frontmatter and inline tags"`
	Properties map[string]any `json:"properties" jsonschema:"decoded frontmatter"`
	Created    string         `json:"created,omitempty" jsonschema:"RFC 3339"`
	Updated    string         `json:"updated,omitempty" jsonschema:"RFC 3339"`
	Modified   string         `json:"modified" jsonschema:"file modification time, RFC 3339"`
	Snippet    string         `json:"snippet,omitempty" jsonschema:"matching text, for search results"`
}

NoteInfo describes a note without its content.

type NoteInput

type NoteInput struct {
	Note string `` /* 127-byte string literal not displayed */
}

NoteInput names one note.

type NotesOutput

type NotesOutput struct {
	Notes []NoteInfo `json:"notes"`
	Count int        `json:"count"`
}

NotesOutput is a list of notes.

type SearchInput

type SearchInput struct {
	Query  string `` /* 160-byte string literal not displayed */
	Folder string `json:"folder,omitempty" jsonschema:"only notes in this folder and its subfolders"`
	Tag    string `json:"tag,omitempty" jsonschema:"only notes with this tag (nested tags included)"`
	Limit  int    `json:"limit,omitempty" jsonschema:"maximum number of results (default 20)"`
}

SearchInput are the arguments of search_notes.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service runs the MCP tools against one vault and its index. It is safe for concurrent use; calls are serialized.

func NewService

func NewService(v *vault.Vault, ix *index.Index) *Service

NewService returns a service for v. ix is the vault's index; Service brings it up to date with the files before every call, so edits made outside (an editor, sync, the CLI) are seen.

func NewServiceLocked

func NewServiceLocked(v *vault.Vault, ix *index.Index, mu sync.Locker) *Service

NewServiceLocked is NewService with calls serialized by mu, a lock the caller shares with other writers of the vault (the sync server holds it for every change to a vault's working copy).

func (*Service) Append

func (s *Service) Append(in AppendInput) (Note, error)

Append adds text to the end of a note.

func (s *Service) Backlinks(in NoteInput) (BacklinksOutput, error)

Backlinks lists the notes linking to a note.

func (*Service) Create

func (s *Service) Create(in CreateInput) (Note, error)

Create makes a new note and returns it. Hooks may have moved or edited it by the time it is returned; the result shows where it ended up.

func (*Service) Frontmatter

func (s *Service) Frontmatter(in FrontmatterInput) (Note, error)

Frontmatter sets and removes frontmatter keys. Only those keys' lines (and updated) change.

func (*Service) List

func (s *Service) List(in ListInput) (NotesOutput, error)

List lists notes by folder, tag, properties or view.

func (*Service) Move

func (s *Service) Move(in MoveInput) (MoveOutput, error)

Move moves a note to another folder, keeping its file name.

func (*Service) Read

func (s *Service) Read(in NoteInput) (Note, error)

Read returns a note with its content.

func (*Service) ReadPath

func (s *Service) ReadPath(p string) (Note, error)

ReadPath reads a note by exact vault path, for resources.

func (*Service) Search

func (s *Service) Search(in SearchInput) (NotesOutput, error)

Search runs a full-text search.

func (*Service) Tags

func (s *Service) Tags() (TagsOutput, error)

Tags lists every tag with its note count.

func (*Service) Update

func (s *Service) Update(in UpdateInput) (Note, error)

Update replaces the body of a note, keeping its frontmatter.

func (*Service) Views

func (s *Service) Views() (ViewsOutput, error)

Views lists the saved views in .nota/views/.

type TagsOutput

type TagsOutput struct {
	Tags []index.TagCount `json:"tags"`
}

TagsOutput is the result of list_tags.

type UpdateInput

type UpdateInput struct {
	Note         string `json:"note" jsonschema:"the note: a path, title, unique prefix or nota://note/ URI"`
	Body         string `json:"body" jsonschema:"the new markdown body; the frontmatter is kept"`
	ExpectedHash string `json:"expected_hash,omitempty" jsonschema:"hash from read_note; when given, the update fails if the note changed since"`
}

UpdateInput are the arguments of update_note.

type View

type View struct {
	ID     string         `json:"id" jsonschema:"pass as view to list_notes"`
	Name   string         `json:"name"`
	Where  map[string]any `json:"where,omitempty"`
	Tag    string         `json:"tag,omitempty"`
	Folder string         `json:"folder,omitempty"`
	Sort   string         `json:"sort,omitempty"`
	Count  int            `json:"count"`
}

View is a saved view with its note count.

type ViewsOutput

type ViewsOutput struct {
	Views []View `json:"views"`
}

ViewsOutput is the result of list_views.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL