GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — MCP: func://function resource reads the server's working directory, not the agent's Function · Issue #4204 · knative/func Todo DescriptionSummaryThe This contradicts ReproductionThe script below creates two Functions ( Output on repro_function_resource.py#!/usr/bin/env python3 """ Reproduce: the func MCP server's `func://function` resource reads func.yaml from the MCP server's own working directory. Resources take no arguments, so an agent cannot point it at the Function it is working on. The script creates two Functions (app-a, app-b) and an empty directory in a temporary folder, then starts the real `func mcp start` server three times and reads `func://function`, as an agent working on app-b would. Usage: python3 repro_function_resource.py Requirements: `func` on your PATH, Python 3 (standard library only). Nothing outside the temporary folder is touched, and no cluster is needed. """ import json import os import shutil import subprocess import sys import tempfile def read_resource(func, cwd, uri): """Start `func mcp start` in cwd, read one resource, return a short result.""" server = subprocess.Popen( [func, "mcp", "start"], cwd=cwd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, ) def send(msg): server.stdin.write(json.dumps(msg) + "\n") server.stdin.flush() def wait_for(msg_id): while True: line = server.stdout.readline() if not line: sys.exit("MCP server exited unexpectedly") msg = json.loads(line) if msg.get("id") == msg_id: return msg try: send({"jsonrpc": "2.0", "id": 0, "method": "initialize", "params": { "protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "repro", "version": "0"}}}) wait_for(0) send({"jsonrpc": "2.0", "method": "notifications/initialized"}) send({"jsonrpc": "2.0", "id": 1, "method": "resources/read", "params": {"uri": uri}}) msg = wait_for(1) finally: server.stdin.close() server.wait(timeout=30) if "error" in msg: return "error: " + msg["error"].get("message", "") text = msg["result"]["contents"][0]["text"] try: state = json.loads(text) except ValueError: return text.strip() # plain-text error from the handler return f"Function {state.get('Name')!r} (func.yaml in {state.get('Root')!r})" def main(): func = shutil.which("func") if not func: sys.exit("`func` must be on PATH") tmp = tempfile.mkdtemp(prefix="func-resource-") app_a = os.path.join(tmp, "app-a") app_b = os.path.join(tmp, "app-b") empty = os.path.join(tmp, "empty") os.mkdir(empty) for path in (app_a, app_b): subprocess.run([func, "create", "-l", "go", path], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) print(f"func: {func}") print("The agent is working on app-b.\n") cases = [ ("server started in an empty directory", empty, "func://function"), ("server started in another Function (app-a)", app_a, "func://function"), ("asking for app-b by path", empty, "func://function?path=" + app_b), ] for desc, cwd, uri in cases: print(desc) print(f" read {uri.replace(tmp, '<tmp>')}") print(f" -> {read_resource(func, cwd, uri).replace(tmp, '<tmp>')}\n") shutil.rmtree(tmp, ignore_errors=True) if __name__ == "__main__": main() ImpactLow: the resource is read-only. But where the client starts the server outside the project, the resource either finds no Function, or, if that directory holds a different Function, silently returns that Function's configuration. An agent can then act on the wrong Function's settings with no error to warn it. The resource description says "(from working directory)", so reading the working directory may have been intended. With the absolute- Possible fixes
Option 1 seems the smallest change that keeps the resource useful. Which would you prefer? I'd like to work on this and will open a PR with the fix and tests once we agree on the approach. Could it be assigned to me? Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |