opencode-lazy-loader 1.0.0
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/LICENSE +21 -0
- package/README.md +141 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 keybrdist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# OpenCode Lazy Loader Plugin
|
|
2
|
+
|
|
3
|
+
This is the OpenCode plugin that lazy-loads skill-embedded MCP servers. It lets skills bundle their own MCP servers so they can be loaded on-demand instead of being configured globally.
|
|
4
|
+
|
|
5
|
+
Note: This package was renamed from `opencode-embedded-skill-mcp` to `opencode-lazy-loader`. If you still have the old package, upgrade to the new name.
|
|
6
|
+
|
|
7
|
+
This is a standalone OpenCode plugin that enables skills to bundle and manage their own [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers, then lazy-load them on demand.
|
|
8
|
+
|
|
9
|
+
This allows skills to bring their own tools, resources, and prompts without requiring manual server configuration in `opencode.json`.
|
|
10
|
+
|
|
11
|
+
## Why use this?
|
|
12
|
+
|
|
13
|
+
- **Plug-and-Play Skills**: Skills bring their own tools. No need to manually register servers in your global config.
|
|
14
|
+
- **Cleaner Context**: Tools are loaded on-demand only when the skill is active, keeping your agent's context window focused and efficient.
|
|
15
|
+
- **Team Portability**: Commit skills to your project repo; anyone with the plugin gets the tools automatically.
|
|
16
|
+
- **Efficient Resources**: Servers start only when used and shut down automatically after 5 minutes of inactivity.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Technical Features
|
|
21
|
+
|
|
22
|
+
- **Skill-Embedded MCPs**: Configure MCP servers directly within skill definitions (markdown frontmatter or `mcp.json`).
|
|
23
|
+
- **Zero Configuration**: Skills manage their own MCP connections; just load the skill and use the tools.
|
|
24
|
+
- **Connection Management**:
|
|
25
|
+
- Connection pooling per session/skill/server.
|
|
26
|
+
- Lazy connection initialization (connects on first use).
|
|
27
|
+
- Automatic idle cleanup (disconnects after 5 minutes of inactivity).
|
|
28
|
+
- Session-scoped resource cleanup.
|
|
29
|
+
- **Environment Variable Support**: Full support for `${VAR}` and `${VAR:-default}` expansion in MCP configurations.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Deprecation notice: The package was renamed from `opencode-embedded-skill-mcp` to `opencode-lazy-loader`. If you installed the old name, update to the new package.
|
|
34
|
+
|
|
35
|
+
Add the plugin to your `opencode.json`:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"plugin": ["opencode-lazy-loader"]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or install it locally:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"plugin": ["./path/to/opencode-lazy-loader"]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### 1. Create a Skill with Embedded MCP
|
|
54
|
+
|
|
55
|
+
You can define MCP servers in the skill's YAML frontmatter:
|
|
56
|
+
|
|
57
|
+
**`~/.config/opencode/skill/my-skill/SKILL.md`**
|
|
58
|
+
|
|
59
|
+
```markdown
|
|
60
|
+
---
|
|
61
|
+
name: browser-automation
|
|
62
|
+
description: "A skill for automating browser interactions"
|
|
63
|
+
mcp:
|
|
64
|
+
playwright:
|
|
65
|
+
command: ["npx", "-y", "@playwright/mcp@latest"]
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
# Browser Automation
|
|
69
|
+
|
|
70
|
+
This skill provides browser automation tools via the `playwright` MCP.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Alternatively, place an `mcp.json` file in the skill directory:
|
|
74
|
+
|
|
75
|
+
**`~/.config/opencode/skill/browser-automation/mcp.json`**
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"mcpServers": {
|
|
80
|
+
"playwright": {
|
|
81
|
+
"command": ["npx", "-y", "@playwright/mcp@latest"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 2. Load the Skill
|
|
88
|
+
|
|
89
|
+
In OpenCode:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
skill(name="browser-automation")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Pro Tip:** You don't always need to call the tool explicitly. Just ask for the skill by name in chat, and OpenCode will usually find and load it for you:
|
|
96
|
+
|
|
97
|
+
> "Use the browser-automation skill to take a screenshot of google.com"
|
|
98
|
+
|
|
99
|
+
The plugin will load the skill and discover the capabilities of the embedded MCP server.
|
|
100
|
+
|
|
101
|
+
### 3. Use MCP Tools
|
|
102
|
+
|
|
103
|
+
Invoke tools, read resources, or get prompts using `skill_mcp`:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
skill_mcp(mcp_name="playwright", tool_name="screenshot", arguments='{"url": "https://google.com"}')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Tools Provided
|
|
110
|
+
|
|
111
|
+
### `skill`
|
|
112
|
+
|
|
113
|
+
Loads a skill and displays its instructions along with any available MCP capabilities (tools, resources, prompts).
|
|
114
|
+
|
|
115
|
+
- **name**: The name of the skill to load.
|
|
116
|
+
|
|
117
|
+
### `skill_mcp`
|
|
118
|
+
|
|
119
|
+
Invokes an operation on a skill-embedded MCP server.
|
|
120
|
+
|
|
121
|
+
- **mcp_name**: The name of the MCP server (defined in the skill config).
|
|
122
|
+
- **tool_name**: (Optional) The name of the tool to call.
|
|
123
|
+
- **resource_name**: (Optional) The URI of the resource to read.
|
|
124
|
+
- **prompt_name**: (Optional) The name of the prompt to get.
|
|
125
|
+
- **arguments**: (Optional) JSON string of arguments for the operation.
|
|
126
|
+
- **grep**: (Optional) Regex pattern to filter the output.
|
|
127
|
+
|
|
128
|
+
## Configuration Format
|
|
129
|
+
|
|
130
|
+
The MCP configuration supports the standard format:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
interface McpServerConfig {
|
|
134
|
+
command: string | string[]; // Command to execute (array recommended for args)
|
|
135
|
+
environment?: Record<string, string> // Environment variables
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-lazy-loader",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "OpenCode plugin for lazy-loading skill-embedded MCP servers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"watch": "tsc --watch",
|
|
11
|
+
"clean": "rm -rf dist"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"opencode",
|
|
15
|
+
"plugin",
|
|
16
|
+
"mcp",
|
|
17
|
+
"skill"
|
|
18
|
+
],
|
|
19
|
+
"author": "keybrdist",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/keybrdist/opencode-lazy-loader.git"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
32
|
+
"@opencode-ai/plugin": "^1.1.23",
|
|
33
|
+
"js-yaml": "^4.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/js-yaml": "^4.0.9",
|
|
37
|
+
"@types/node": "^22.0.0",
|
|
38
|
+
"typescript": "^5.7.0"
|
|
39
|
+
}
|
|
40
|
+
}
|