@aws/agentcore 1.0.0-preview.11 → 1.0.0-preview.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-inspector/index.css +1 -1
- package/dist/agent-inspector/index.js +83 -78
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +446 -144
- package/dist/assets/cdk/bin/cdk.ts +4 -0
- package/dist/assets/cdk/lib/cdk-stack.ts +2 -0
- package/dist/assets/cdk/package.json +1 -1
- package/dist/assets/python/a2a/googleadk/base/main.py +24 -16
- package/dist/assets/python/a2a/langchain_langgraph/base/main.py +24 -16
- package/dist/assets/python/a2a/strands/base/main.py +23 -17
- package/dist/assets/python/agui/googleadk/base/main.py +62 -2
- package/dist/assets/python/agui/langchain_langgraph/base/main.py +56 -0
- package/dist/assets/python/agui/strands/base/main.py +63 -1
- package/dist/assets/python/http/autogen/base/main.py +27 -19
- package/dist/assets/python/http/googleadk/base/main.py +24 -16
- package/dist/assets/python/http/langchain_langgraph/base/main.py +24 -16
- package/dist/assets/python/http/openaiagents/base/main.py +24 -16
- package/dist/assets/python/http/strands/base/main.py +23 -17
- package/dist/assets/python/mcp/standalone/base/main.py +58 -0
- package/dist/cli/index.mjs +685 -639
- package/dist/lib/errors/types.d.ts +3 -0
- package/dist/lib/errors/types.d.ts.map +1 -1
- package/dist/lib/errors/types.js +10 -1
- package/dist/lib/errors/types.js.map +1 -1
- package/dist/lib/errors/zod.js +1 -1
- package/dist/lib/errors/zod.js.map +1 -1
- package/dist/lib/result.d.ts +6 -4
- package/dist/lib/result.d.ts.map +1 -1
- package/dist/lib/result.js +7 -0
- package/dist/lib/result.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +50 -4
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +102 -4
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +12 -2
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/harness.d.ts +8 -0
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/harness.js +23 -0
- package/dist/schema/schemas/primitives/harness.js.map +1 -1
- package/npm-shrinkwrap.json +281 -366
- package/package.json +12 -7
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
{{#if needsOs}}
|
|
1
2
|
import os
|
|
3
|
+
{{/if}}
|
|
2
4
|
from google.adk.agents import Agent
|
|
3
5
|
from google.adk.runners import Runner
|
|
4
6
|
from google.adk.sessions import InMemorySessionService
|
|
@@ -29,18 +31,21 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
29
31
|
# Define a collection of tools used by the model
|
|
30
32
|
tools = [add_numbers]
|
|
31
33
|
|
|
32
|
-
{{#if
|
|
33
|
-
|
|
34
|
+
{{#if needsOs}}
|
|
35
|
+
_MOUNT_PATHS = [
|
|
36
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
37
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
38
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
39
|
+
]
|
|
34
40
|
|
|
35
41
|
def _safe_resolve(path: str) -> str:
|
|
36
|
-
|
|
37
|
-
resolved
|
|
38
|
-
|
|
39
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
42
|
+
resolved = os.path.realpath(path)
|
|
43
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
44
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
40
45
|
return resolved
|
|
41
46
|
|
|
42
47
|
def file_read(path: str) -> str:
|
|
43
|
-
"""Read a file from
|
|
48
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
44
49
|
try:
|
|
45
50
|
full_path = _safe_resolve(path)
|
|
46
51
|
with open(full_path) as f:
|
|
@@ -51,7 +56,7 @@ def file_read(path: str) -> str:
|
|
|
51
56
|
return f"Error reading '{path}': {e.strerror}"
|
|
52
57
|
|
|
53
58
|
def file_write(path: str, content: str) -> str:
|
|
54
|
-
"""Write
|
|
59
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
55
60
|
try:
|
|
56
61
|
full_path = _safe_resolve(path)
|
|
57
62
|
parent = os.path.dirname(full_path)
|
|
@@ -65,25 +70,28 @@ def file_write(path: str, content: str) -> str:
|
|
|
65
70
|
except OSError as e:
|
|
66
71
|
return f"Error writing '{path}': {e.strerror}"
|
|
67
72
|
|
|
68
|
-
def list_files(
|
|
69
|
-
"""List files in
|
|
73
|
+
def list_files(path: str) -> str:
|
|
74
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
70
75
|
try:
|
|
71
|
-
|
|
72
|
-
entries = os.listdir(
|
|
76
|
+
full_path = _safe_resolve(path)
|
|
77
|
+
entries = os.listdir(full_path)
|
|
73
78
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
74
79
|
except ValueError as e:
|
|
75
80
|
return str(e)
|
|
76
81
|
except OSError as e:
|
|
77
|
-
return f"Error listing '{
|
|
82
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
78
83
|
|
|
79
84
|
tools.extend([file_read, file_write, list_files])
|
|
80
85
|
{{/if}}
|
|
81
86
|
|
|
82
87
|
AGENT_INSTRUCTION = """
|
|
83
88
|
I can answer your questions using the knowledge I have!
|
|
84
|
-
{{#if
|
|
85
|
-
You have
|
|
86
|
-
{{
|
|
89
|
+
{{#if needsOs}}
|
|
90
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
91
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
92
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
93
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
94
|
+
{{/each}}{{/if}}
|
|
87
95
|
"""
|
|
88
96
|
|
|
89
97
|
# Get MCP Toolset
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
{{#if needsOs}}
|
|
1
2
|
import os
|
|
3
|
+
{{/if}}
|
|
2
4
|
from typing import Any
|
|
3
5
|
|
|
4
6
|
from langchain_core.messages import HumanMessage{{#if hasConfigBundle}}, SystemMessage{{/if}}
|
|
@@ -33,9 +35,12 @@ def get_or_create_model():
|
|
|
33
35
|
|
|
34
36
|
DEFAULT_SYSTEM_PROMPT = """
|
|
35
37
|
You are a helpful assistant. Use tools when appropriate.
|
|
36
|
-
{{#if
|
|
37
|
-
You have
|
|
38
|
-
{{
|
|
38
|
+
{{#if needsOs}}
|
|
39
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
40
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
41
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
42
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
43
|
+
{{/each}}{{/if}}
|
|
39
44
|
"""
|
|
40
45
|
|
|
41
46
|
|
|
@@ -49,19 +54,22 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
49
54
|
# Define a collection of tools used by the model
|
|
50
55
|
tools = [add_numbers]
|
|
51
56
|
|
|
52
|
-
{{#if
|
|
53
|
-
|
|
57
|
+
{{#if needsOs}}
|
|
58
|
+
_MOUNT_PATHS = [
|
|
59
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
60
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
61
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
62
|
+
]
|
|
54
63
|
|
|
55
64
|
def _safe_resolve(path: str) -> str:
|
|
56
|
-
|
|
57
|
-
resolved
|
|
58
|
-
|
|
59
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
65
|
+
resolved = os.path.realpath(path)
|
|
66
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
67
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
60
68
|
return resolved
|
|
61
69
|
|
|
62
70
|
@tool
|
|
63
71
|
def file_read(path: str) -> str:
|
|
64
|
-
"""Read a file from
|
|
72
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
65
73
|
try:
|
|
66
74
|
full_path = _safe_resolve(path)
|
|
67
75
|
with open(full_path) as f:
|
|
@@ -73,7 +81,7 @@ def file_read(path: str) -> str:
|
|
|
73
81
|
|
|
74
82
|
@tool
|
|
75
83
|
def file_write(path: str, content: str) -> str:
|
|
76
|
-
"""Write
|
|
84
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
77
85
|
try:
|
|
78
86
|
full_path = _safe_resolve(path)
|
|
79
87
|
parent = os.path.dirname(full_path)
|
|
@@ -88,16 +96,16 @@ def file_write(path: str, content: str) -> str:
|
|
|
88
96
|
return f"Error writing '{path}': {e.strerror}"
|
|
89
97
|
|
|
90
98
|
@tool
|
|
91
|
-
def list_files(
|
|
92
|
-
"""List files in
|
|
99
|
+
def list_files(path: str) -> str:
|
|
100
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
93
101
|
try:
|
|
94
|
-
|
|
95
|
-
entries = os.listdir(
|
|
102
|
+
full_path = _safe_resolve(path)
|
|
103
|
+
entries = os.listdir(full_path)
|
|
96
104
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
97
105
|
except ValueError as e:
|
|
98
106
|
return str(e)
|
|
99
107
|
except OSError as e:
|
|
100
|
-
return f"Error listing '{
|
|
108
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
101
109
|
|
|
102
110
|
tools.extend([file_read, file_write, list_files])
|
|
103
111
|
{{/if}}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
{{#if needsOs}}
|
|
1
2
|
import os
|
|
3
|
+
{{/if}}
|
|
2
4
|
from agents import Agent, Runner, function_tool
|
|
3
5
|
from bedrock_agentcore.runtime import BedrockAgentCoreApp
|
|
4
6
|
from model.load import load_model
|
|
@@ -37,19 +39,22 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
37
39
|
|
|
38
40
|
tools = [add_numbers]
|
|
39
41
|
|
|
40
|
-
{{#if
|
|
41
|
-
|
|
42
|
+
{{#if needsOs}}
|
|
43
|
+
_MOUNT_PATHS = [
|
|
44
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
45
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
46
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
47
|
+
]
|
|
42
48
|
|
|
43
49
|
def _safe_resolve(path: str) -> str:
|
|
44
|
-
|
|
45
|
-
resolved
|
|
46
|
-
|
|
47
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
50
|
+
resolved = os.path.realpath(path)
|
|
51
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
52
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
48
53
|
return resolved
|
|
49
54
|
|
|
50
55
|
@function_tool
|
|
51
56
|
def file_read(path: str) -> str:
|
|
52
|
-
"""Read a file from
|
|
57
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
53
58
|
try:
|
|
54
59
|
full_path = _safe_resolve(path)
|
|
55
60
|
with open(full_path) as f:
|
|
@@ -61,7 +66,7 @@ def file_read(path: str) -> str:
|
|
|
61
66
|
|
|
62
67
|
@function_tool
|
|
63
68
|
def file_write(path: str, content: str) -> str:
|
|
64
|
-
"""Write
|
|
69
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
65
70
|
try:
|
|
66
71
|
full_path = _safe_resolve(path)
|
|
67
72
|
parent = os.path.dirname(full_path)
|
|
@@ -76,25 +81,28 @@ def file_write(path: str, content: str) -> str:
|
|
|
76
81
|
return f"Error writing '{path}': {e.strerror}"
|
|
77
82
|
|
|
78
83
|
@function_tool
|
|
79
|
-
def list_files(
|
|
80
|
-
"""List files in
|
|
84
|
+
def list_files(path: str) -> str:
|
|
85
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
81
86
|
try:
|
|
82
|
-
|
|
83
|
-
entries = os.listdir(
|
|
87
|
+
full_path = _safe_resolve(path)
|
|
88
|
+
entries = os.listdir(full_path)
|
|
84
89
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
85
90
|
except ValueError as e:
|
|
86
91
|
return str(e)
|
|
87
92
|
except OSError as e:
|
|
88
|
-
return f"Error listing '{
|
|
93
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
89
94
|
|
|
90
95
|
tools.extend([file_read, file_write, list_files])
|
|
91
96
|
{{/if}}
|
|
92
97
|
|
|
93
98
|
INSTRUCTIONS = """
|
|
94
99
|
You are a helpful assistant. Use tools when appropriate.
|
|
95
|
-
{{#if
|
|
96
|
-
You have
|
|
97
|
-
{{
|
|
100
|
+
{{#if needsOs}}
|
|
101
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
102
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
103
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
104
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
105
|
+
{{/each}}{{/if}}
|
|
98
106
|
"""
|
|
99
107
|
|
|
100
108
|
# Define the agent execution
|
|
@@ -15,7 +15,7 @@ from mcp_client.client import get_streamable_http_mcp_client
|
|
|
15
15
|
{{#if hasMemory}}
|
|
16
16
|
from memory.session import get_memory_session_manager
|
|
17
17
|
{{/if}}
|
|
18
|
-
{{#if
|
|
18
|
+
{{#if needsOs}}
|
|
19
19
|
import os
|
|
20
20
|
{{/if}}
|
|
21
21
|
|
|
@@ -31,9 +31,12 @@ mcp_clients = [get_streamable_http_mcp_client()]
|
|
|
31
31
|
|
|
32
32
|
DEFAULT_SYSTEM_PROMPT = """
|
|
33
33
|
You are a helpful assistant. Use tools when appropriate.
|
|
34
|
-
{{#if
|
|
35
|
-
You have
|
|
36
|
-
{{
|
|
34
|
+
{{#if needsOs}}
|
|
35
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
36
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
37
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
38
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
39
|
+
{{/each}}{{/if}}
|
|
37
40
|
"""
|
|
38
41
|
|
|
39
42
|
{{#if hasConfigBundle}}
|
|
@@ -54,19 +57,22 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
54
57
|
return a+b
|
|
55
58
|
tools.append(add_numbers)
|
|
56
59
|
|
|
57
|
-
{{#if
|
|
58
|
-
|
|
60
|
+
{{#if needsOs}}
|
|
61
|
+
_MOUNT_PATHS = [
|
|
62
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
63
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
64
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
65
|
+
]
|
|
59
66
|
|
|
60
67
|
def _safe_resolve(path: str) -> str:
|
|
61
|
-
|
|
62
|
-
resolved
|
|
63
|
-
|
|
64
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
68
|
+
resolved = os.path.realpath(path)
|
|
69
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
70
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
65
71
|
return resolved
|
|
66
72
|
|
|
67
73
|
@tool
|
|
68
74
|
def file_read(path: str) -> str:
|
|
69
|
-
"""Read a file from
|
|
75
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
70
76
|
try:
|
|
71
77
|
full_path = _safe_resolve(path)
|
|
72
78
|
with open(full_path) as f:
|
|
@@ -78,7 +84,7 @@ def file_read(path: str) -> str:
|
|
|
78
84
|
|
|
79
85
|
@tool
|
|
80
86
|
def file_write(path: str, content: str) -> str:
|
|
81
|
-
"""Write
|
|
87
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
82
88
|
try:
|
|
83
89
|
full_path = _safe_resolve(path)
|
|
84
90
|
parent = os.path.dirname(full_path)
|
|
@@ -93,16 +99,16 @@ def file_write(path: str, content: str) -> str:
|
|
|
93
99
|
return f"Error writing '{path}': {e.strerror}"
|
|
94
100
|
|
|
95
101
|
@tool
|
|
96
|
-
def list_files(
|
|
97
|
-
"""List files in
|
|
102
|
+
def list_files(path: str) -> str:
|
|
103
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
98
104
|
try:
|
|
99
|
-
|
|
100
|
-
entries = os.listdir(
|
|
105
|
+
full_path = _safe_resolve(path)
|
|
106
|
+
entries = os.listdir(full_path)
|
|
101
107
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
102
108
|
except ValueError as e:
|
|
103
109
|
return str(e)
|
|
104
110
|
except OSError as e:
|
|
105
|
-
return f"Error listing '{
|
|
111
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
106
112
|
|
|
107
113
|
tools.extend([file_read, file_write, list_files])
|
|
108
114
|
{{/if}}
|
|
@@ -1,7 +1,65 @@
|
|
|
1
|
+
{{#if needsOs}}
|
|
2
|
+
import os
|
|
3
|
+
{{/if}}
|
|
1
4
|
from mcp.server.fastmcp import FastMCP
|
|
2
5
|
|
|
3
6
|
mcp = FastMCP("{{ name }}", host="0.0.0.0", stateless_http=True)
|
|
4
7
|
|
|
8
|
+
{{#if needsOs}}
|
|
9
|
+
_MOUNT_PATHS = [
|
|
10
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
11
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
12
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def _safe_resolve(path: str) -> str:
|
|
16
|
+
resolved = os.path.realpath(path)
|
|
17
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
18
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
19
|
+
return resolved
|
|
20
|
+
|
|
21
|
+
@mcp.tool()
|
|
22
|
+
def file_read(path: str) -> str:
|
|
23
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
24
|
+
try:
|
|
25
|
+
full_path = _safe_resolve(path)
|
|
26
|
+
with open(full_path) as f:
|
|
27
|
+
return f.read()
|
|
28
|
+
except ValueError as e:
|
|
29
|
+
return str(e)
|
|
30
|
+
except OSError as e:
|
|
31
|
+
return f"Error reading '{path}': {e.strerror}"
|
|
32
|
+
|
|
33
|
+
@mcp.tool()
|
|
34
|
+
def file_write(path: str, content: str) -> str:
|
|
35
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
36
|
+
try:
|
|
37
|
+
full_path = _safe_resolve(path)
|
|
38
|
+
parent = os.path.dirname(full_path)
|
|
39
|
+
if parent:
|
|
40
|
+
os.makedirs(parent, exist_ok=True)
|
|
41
|
+
with open(full_path, "w") as f:
|
|
42
|
+
f.write(content)
|
|
43
|
+
return f"Written to {path}"
|
|
44
|
+
except ValueError as e:
|
|
45
|
+
return str(e)
|
|
46
|
+
except OSError as e:
|
|
47
|
+
return f"Error writing '{path}': {e.strerror}"
|
|
48
|
+
|
|
49
|
+
@mcp.tool()
|
|
50
|
+
def list_files(path: str) -> str:
|
|
51
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
52
|
+
try:
|
|
53
|
+
full_path = _safe_resolve(path)
|
|
54
|
+
entries = os.listdir(full_path)
|
|
55
|
+
return "\n".join(entries) if entries else "(empty directory)"
|
|
56
|
+
except ValueError as e:
|
|
57
|
+
return str(e)
|
|
58
|
+
except OSError as e:
|
|
59
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
60
|
+
|
|
61
|
+
{{/if}}
|
|
62
|
+
|
|
5
63
|
|
|
6
64
|
@mcp.tool()
|
|
7
65
|
def add_numbers(a: int, b: int) -> int:
|