Skip to main content

mcp

The vault as a set of MCP tools that an AI client such as Claude Desktop can call

MCP, the Model Context Protocol, is how AI assistants and editors call outside tools. vishalakshi-mcp is an MCP server that offers vault methods as tools. TOOLS lists them. Each tool is built with the cmd function that the command line uses. The arguments and the description of a tool are the arguments and the docstring of the method. The instructions of the server tell a model which tool to use first. context comes before answering a question. grab files something. note writes a conclusion back.

The server treats an MCP client as an agent and never as a person. Every tool that takes by is called with by='agent', and the server does not offer by. A client can raise a privacy level or mark a document personal. A client cannot clear a mark, reject a finding or lower a level (see pii).

The client is a model that the vault does not run. Every result passes through client_view before the client sees it. client_view withholds each string under a Local only document, including the title, headings and source. Every other string goes through redact, which masks the identifiers of a Personal document. A document that a person cleared with mark_not_pii comes back as stored. A tool that takes pii defaults to redact here. The CLI defaults to off. A client may ask for refuse, which withholds more. A client may not ask for off. Only a person can turn the gate off, as only a person can lower a level. ask returns no prompt. When a local model read a Local only section whole, its answer is also withheld. To use the server, add it to the configuration of the client:

{"mcpServers": {"vishalakshi": {"command": "vishalakshi-mcp",
                                "env": {"VISHALAKSHI_VAULT": "~/.vishalakshi/vault.db"}}}}

The server talks over standard input and output by default. vishalakshi-mcp --http serves Streamable HTTP instead.


source

main

def main():

Run the vishalakshi-mcp server, over standard input and output, or Streamable HTTP with --http.


source

as_tool

def as_tool(
    name:str
):

Register one Vault method as an MCP tool that returns JSON through client_view. The tool fixes by to 'agent' and hides it. The default of pii is redact.


source

client_view

def client_view(
    o, v, ner:bool=False
):

Return what an MCP client receives for a result. Each string under a Local only document is withheld. Every other string goes through redact, except in a cleared document, which is returned as stored. The result has no prompt.

Try it

tools = {t.name: t for t in await mcp.list_tools()}
len(tools), tools['context'].description[:120]
(47,
 'The retrieval an LLM should be handed: whole sections plus what they connect to. sections carry `text, breadcrumb, pages')
import os, tempfile
from pathlib import Path
from vishalakshi import Vault
from vishalakshi.cli import vault
def schema(t): return getattr(t, 'input_schema', None) or t.inputSchema   # renamed in mcp 2.0

test_eq(sorted(tools), sorted(TOOLS))
test_eq(schema(tools['search'])['properties']['limit']['default'], 10)
test_eq(schema(tools['search'])['required'], ['q'])
# the docments on the Vault method are what a client reads, so they have to survive the round trip
assert 'invoice' in tools['categorize'].description
test_eq(schema(tools['extract'])['required'], ['ref'])
test_eq(schema(tools['ask_doc'])['required'], ['ref', 'question'])
# an MCP client is an agent: it cannot say it is a person, so it cannot clear a mark
assert 'by' not in schema(tools['mark_not_pii'])['properties']
_mv = Vault(str(Path(tempfile.mkdtemp())/'m.db'), offline=True)
_mv.note('A letter about the garden.', title='letter')
_old = {k: os.environ.get(k) for k in ('VISHALAKSHI_VAULT', 'VISHALAKSHI_OFFLINE')}
os.environ.update(VISHALAKSHI_VAULT=str(_mv.path), VISHALAKSHI_OFFLINE='1'); vault.cache_clear()
try:
    await mcp.call_tool('mark_not_pii', dict(ref='letter'))
    _err = ''
except Exception as e: _err = str(e)
assert 'person' in _err, _err
test_eq(_mv.marks('letter').get('pii_override'), None)
for _k, _x in _old.items():
    if _x is None: os.environ.pop(_k, None)
    else: os.environ[_k] = _x
vault.cache_clear()
from vishalakshi.ask import use_chat
# what a client is handed by default: no Personal identifier and nothing of a Local only document, title included
_pv = Vault(str(Path(tempfile.mkdtemp())/'p.db'), offline=True)
_pv.note('Write to jane.doe@example.com about the orchard and the garden wall.', title='orchard letter')
_pv.note('The orchard ledger for the garden: what the trees cost.', title='Zanzibar ledger')
_pv.set_level('Zanzibar', 'local')
_pv.note('Rank fusion for the orchard and garden search.', title='fusion note')
_pd, _ld = _pv.doc('orchard letter')['id'], _pv.doc('Zanzibar')['id']
class _Echo:
    "A chat on this machine that repeats its prompt, the most a model could hand back of what it read."
    def __init__(self, model=None, **kw): self.runtime = 'litert'
    def __call__(self, p): return dict(content=p)
_q = dict(q='orchard garden')
_calls = [('search', _q), ('sections', _q), ('context', dict(_q, code=0)), ('federate', _q), ('toc', {}), ('sources', {}),
          ('read', dict(node_id=f'{_ld}#1')), ('read', dict(node_id=f'{_pd}#1')), ('related', dict(node_id=f'{_pd}#1')),
          ('document', dict(ref=_ld)), ('document', dict(ref=_pd)), ('pii', dict(ref=_ld)), ('pii', dict(ref=_pd)),
          ('level', dict(ref=_ld)), ('ner', dict(ref=_pd)), ('ask', dict(question='what about the orchard?', code=0)),
          ('ask_doc', dict(ref=_ld, question='what does it cost?')), ('ask_doc', dict(ref=_pd, question='who to write to?'))]
_old = {k: os.environ.get(k) for k in ('VISHALAKSHI_VAULT', 'VISHALAKSHI_OFFLINE')}
os.environ.update(VISHALAKSHI_VAULT=str(_pv.path), VISHALAKSHI_OFFLINE='1'); vault.cache_clear()
try:
    with use_chat(_Echo): _outs = [(n, str(await mcp.call_tool(n, a))) for n, a in _calls]
    test_eq([(n, w) for n, s in _outs for w in ('jane.doe@example.com', 'Zanzibar') if w in s], [])
    # ids and Open text come through, so the client can still ask again
    assert _ld in dict(_outs)['level'] and 'Rank fusion' in dict(_outs)['search']
    test_eq(schema(tools['search'])['properties']['pii']['default'], 'redact')
    # an agent may ask for more masking, never for less: `off` is a person's call, made at the command line
    assert 'jane.doe' not in str(await mcp.call_tool('read', dict(node_id=f'{_pd}#1', pii='refuse')))
    try: await mcp.call_tool('search', dict(_q, pii='off')); _err = ''
    except Exception as e: _err = str(e)
    assert 'person' in _err, _err
    # a document a person cleared comes back as stored
    _pv.mark_not_pii(_pd)
    assert 'jane.doe@example.com' in str(await mcp.call_tool('document', dict(ref=_pd)))
finally:
    for _k, _x in _old.items():
        if _x is None: os.environ.pop(_k, None)
        else: os.environ[_k] = _x
    vault.cache_clear()