@mcphero/examples 1.1.6
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/.turbo/turbo-build.log +7 -0
- package/.turbo/turbo-check.log +10 -0
- package/.turbo/turbo-lint.log +5 -0
- package/eslint.config.mjs +99 -0
- package/package.json +35 -0
- package/resources/83ede315-6ebc-4b38-b84b-d046a85102db +1 -0
- package/resources/83ede315-6ebc-4b38-b84b-d046a85102db.json +1 -0
- package/resources/9372c0a4-bb5a-4164-a67f-0af5e313a7e4 +1 -0
- package/resources/9372c0a4-bb5a-4164-a67f-0af5e313a7e4.json +1 -0
- package/src/actions/AdminAction.ts +24 -0
- package/src/actions/HelloAction.ts +27 -0
- package/src/actions/TaskAction.ts +23 -0
- package/src/cli.ts +18 -0
- package/src/cliProxy.ts +14 -0
- package/src/fastify.ts +14 -0
- package/src/http.ts +18 -0
- package/src/stdio.ts +14 -0
- package/src/vercel.ts +17 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import eslint from '@eslint/js'
|
|
2
|
+
import stylistic from '@stylistic/eslint-plugin'
|
|
3
|
+
import { defineConfig } from 'eslint/config'
|
|
4
|
+
import tseslint from 'typescript-eslint'
|
|
5
|
+
|
|
6
|
+
export default defineConfig(eslint.configs.recommended, tseslint.configs.recommendedTypeChecked, tseslint.configs.stylisticTypeChecked, {
|
|
7
|
+
languageOptions: {
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: 'tsconfig.json',
|
|
10
|
+
tsconfigRootDir: import.meta.dirname
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
plugins: { '@stylistic': stylistic },
|
|
14
|
+
rules: {
|
|
15
|
+
'@stylistic/space-in-parens': ['error'],
|
|
16
|
+
'@stylistic/comma-spacing': ['error'],
|
|
17
|
+
'@stylistic/no-multi-spaces': ['error'],
|
|
18
|
+
'@stylistic/no-trailing-spaces': ['error'],
|
|
19
|
+
'@stylistic/no-whitespace-before-property': ['error'],
|
|
20
|
+
'@stylistic/array-bracket-newline': ['error', 'consistent'],
|
|
21
|
+
'@stylistic/array-bracket-spacing': ['error'],
|
|
22
|
+
'@stylistic/arrow-spacing': ['error'],
|
|
23
|
+
'@stylistic/arrow-parens': ['error', 'always'],
|
|
24
|
+
'@stylistic/block-spacing': ['error', 'always'],
|
|
25
|
+
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
|
|
26
|
+
'@stylistic/comma-dangle': ['error', 'never'],
|
|
27
|
+
'@stylistic/key-spacing': ['error'],
|
|
28
|
+
'@stylistic/keyword-spacing': ['error'],
|
|
29
|
+
'@stylistic/member-delimiter-style': ['error', { 'multiline': { 'delimiter': 'none' } }],
|
|
30
|
+
'@stylistic/no-extra-semi': ['error'],
|
|
31
|
+
'@stylistic/indent': ['error', 2],
|
|
32
|
+
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }],
|
|
33
|
+
'@stylistic/object-curly-spacing': ['error', 'always'],
|
|
34
|
+
'@stylistic/quotes': ['error', 'single'],
|
|
35
|
+
'@stylistic/semi': ['error', 'never'],
|
|
36
|
+
'@stylistic/space-before-blocks': ['error', 'always'],
|
|
37
|
+
'@stylistic/space-before-function-paren': ['error', { 'anonymous': 'always', 'named': 'never', 'asyncArrow': 'always' }],
|
|
38
|
+
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
|
39
|
+
'@typescript-eslint/array-type': 'off',
|
|
40
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
41
|
+
'@typescript-eslint/ban-types': 'off',
|
|
42
|
+
'@typescript-eslint/consistent-type-assertions': 'off',
|
|
43
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
44
|
+
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
45
|
+
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
|
|
46
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
47
|
+
'@typescript-eslint/no-empty-interface': 'off',
|
|
48
|
+
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
|
49
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
50
|
+
'@typescript-eslint/no-misused-new': 'error',
|
|
51
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
52
|
+
'@typescript-eslint/no-namespace': 'off',
|
|
53
|
+
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
|
54
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
55
|
+
'@typescript-eslint/no-object-literal-type-assertion': 'off',
|
|
56
|
+
'@typescript-eslint/no-parameter-properties': 'off',
|
|
57
|
+
'@typescript-eslint/no-shadow': 'error',
|
|
58
|
+
'@typescript-eslint/no-triple-slash-reference': 'off',
|
|
59
|
+
'@typescript-eslint/no-unused-vars': ['error', {
|
|
60
|
+
'args': 'all',
|
|
61
|
+
'argsIgnorePattern': '^_',
|
|
62
|
+
'caughtErrors': 'all',
|
|
63
|
+
'caughtErrorsIgnorePattern': '^_',
|
|
64
|
+
'destructuredArrayIgnorePattern': '^_',
|
|
65
|
+
'varsIgnorePattern': '^_',
|
|
66
|
+
'ignoreRestSiblings': true
|
|
67
|
+
}],
|
|
68
|
+
'@typescript-eslint/no-use-before-define': 'off',
|
|
69
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
70
|
+
'@typescript-eslint/prefer-for-of': 'error',
|
|
71
|
+
'@typescript-eslint/prefer-interface': 'off',
|
|
72
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
|
73
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
74
|
+
'@typescript-eslint/return-await': 'error',
|
|
75
|
+
'@typescript-eslint/unified-signatures': 'error',
|
|
76
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
|
77
|
+
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
|
78
|
+
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
79
|
+
'@typescript-eslint/no-unsafe-call': 'off',
|
|
80
|
+
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
81
|
+
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
82
|
+
'@typescript-eslint/dot-notation': 'off',
|
|
83
|
+
'@typescript-eslint/prefer-regexp-exec': 'off',
|
|
84
|
+
'@typescript-eslint/require-await': 'off',
|
|
85
|
+
'@typescript-eslint/only-throw-error': ['error', {
|
|
86
|
+
'allow': [
|
|
87
|
+
{ from: 'package', name: 'TypedResponse', package: '@remix-run/server-runtime' },
|
|
88
|
+
{ from: 'lib', name: 'Response' }
|
|
89
|
+
]
|
|
90
|
+
}],
|
|
91
|
+
'@typescript-eslint/no-base-to-string': 'off',
|
|
92
|
+
'@typescript-eslint/restrict-template-expressions': 'off'
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
files: ['eslint.config.mjs'],
|
|
96
|
+
extends: [tseslint.configs.disableTypeChecked]
|
|
97
|
+
}, {
|
|
98
|
+
ignores: ['build', 'tsup.config.ts']
|
|
99
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcphero/examples",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"description": "MCP Hero Examples",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+ssh://git@github.com/atomicbi/mcphero.git",
|
|
8
|
+
"directory": "example"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "build/index.js",
|
|
12
|
+
"types": "build/index.d.ts",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@mcphero/cli": "1.1.6",
|
|
15
|
+
"@mcphero/core": "1.1.6",
|
|
16
|
+
"@mcphero/logger": "1.1.6",
|
|
17
|
+
"@mcphero/fastify": "1.1.6",
|
|
18
|
+
"@mcphero/mcp": "1.1.6"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@eslint/js": "^10.0.1",
|
|
22
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
23
|
+
"@types/node": "^22.0.0",
|
|
24
|
+
"rimraf": "^6.1.3",
|
|
25
|
+
"tsup": "^8.5.1",
|
|
26
|
+
"tsx": "^4.21.0",
|
|
27
|
+
"typescript": "^5.9.3",
|
|
28
|
+
"typescript-eslint": "^8.56.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"lint": "eslint",
|
|
33
|
+
"check": "pnpm lint && pnpm typecheck"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
the secret code is "pirates"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"83ede315-6ebc-4b38-b84b-d046a85102db","name":"SECRET.md","contentType":"text/plain","size":28}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
the secret code is "pirates"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"9372c0a4-bb5a-4164-a67f-0af5e313a7e4","name":"SECRET.md","contentType":"text/plain","size":28}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createAction } from '@mcphero/core'
|
|
2
|
+
import { Logger } from '@mcphero/logger'
|
|
3
|
+
import z from 'zod'
|
|
4
|
+
|
|
5
|
+
export const AdminAction = createAction({
|
|
6
|
+
name: 'admin',
|
|
7
|
+
description: 'Secret admin action',
|
|
8
|
+
input: z.object({
|
|
9
|
+
operation: z.enum(['read', 'write'])
|
|
10
|
+
}),
|
|
11
|
+
args: ['operation'],
|
|
12
|
+
isEnabled: (context) => {
|
|
13
|
+
return context.has('userId') && context.has('role')
|
|
14
|
+
},
|
|
15
|
+
run: async ({ operation }, context) => {
|
|
16
|
+
const logger = context.get<Logger>('logger')
|
|
17
|
+
logger.info(`requesting operation ${operation}`)
|
|
18
|
+
const userId = context.get<string>('userId')
|
|
19
|
+
const role = context.get<string>('role')
|
|
20
|
+
logger.info({ userId, role })
|
|
21
|
+
const success = operation === 'read' || role === 'admin'
|
|
22
|
+
return { operation, role, success }
|
|
23
|
+
}
|
|
24
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createAction } from '@mcphero/core'
|
|
2
|
+
import { Logger } from '@mcphero/logger'
|
|
3
|
+
import z from 'zod'
|
|
4
|
+
|
|
5
|
+
export interface HelloContext {
|
|
6
|
+
session: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const HelloAction = createAction({
|
|
10
|
+
name: 'hello',
|
|
11
|
+
description: 'Say hello',
|
|
12
|
+
input: z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
type: z.enum(['cat', 'dog'])
|
|
15
|
+
}),
|
|
16
|
+
args: ['name'],
|
|
17
|
+
isEnabled: (context) => {
|
|
18
|
+
const adapter = context.get<string>('adapter')
|
|
19
|
+
return adapter === 'cli'
|
|
20
|
+
},
|
|
21
|
+
run: async ({ name, type }, context) => {
|
|
22
|
+
const logger = context.get<Logger>('logger')
|
|
23
|
+
const message = `Hello, ${name}, my ${type}`
|
|
24
|
+
logger.info(message)
|
|
25
|
+
return { message }
|
|
26
|
+
}
|
|
27
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createAction, createSideloadResource } from '@mcphero/core'
|
|
2
|
+
import { Logger } from '@mcphero/logger'
|
|
3
|
+
import z from 'zod'
|
|
4
|
+
|
|
5
|
+
export const TaskAction = createAction({
|
|
6
|
+
name: 'task',
|
|
7
|
+
description: 'Execute a long-running task',
|
|
8
|
+
input: z.object({
|
|
9
|
+
stepCount: z.number().int().min(1).max(10).describe('Number of steps to execute').default(5),
|
|
10
|
+
stepDuration: z.number().int().min(1000).max(10000).describe('Time duration per step').default(1000)
|
|
11
|
+
}),
|
|
12
|
+
run: async ({ stepCount, stepDuration }, context) => {
|
|
13
|
+
const logger = context.get<Logger>('logger')
|
|
14
|
+
logger.info(`Running ${stepCount} steps at ${stepDuration}ms each`)
|
|
15
|
+
for (let i = 1; i <= stepCount; i += 1) {
|
|
16
|
+
logger.progress({ progress: i, total: stepCount, message: `Executing step ${i} of ${stepCount}` })
|
|
17
|
+
await new Promise((resolve) => { setTimeout(resolve, stepDuration) })
|
|
18
|
+
}
|
|
19
|
+
const buffer = Buffer.from('the secret code is "pirates"', 'utf-8')
|
|
20
|
+
const resource = await createSideloadResource(buffer, { name: 'SECRET.md', contentType: 'text/plain' })
|
|
21
|
+
return { completed: stepCount, resources: [resource] }
|
|
22
|
+
}
|
|
23
|
+
})
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cli } from '@mcphero/cli'
|
|
2
|
+
import { mcphero } from '@mcphero/core'
|
|
3
|
+
import { AdminAction } from './actions/AdminAction.js'
|
|
4
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
5
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
9
|
+
.set('userId', 'toby')
|
|
10
|
+
.set('role', 'admin')
|
|
11
|
+
.adapter(cli())
|
|
12
|
+
.action(HelloAction)
|
|
13
|
+
.action(TaskAction)
|
|
14
|
+
.action(AdminAction)
|
|
15
|
+
.start()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
main()
|
package/src/cliProxy.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mcphero } from '@mcphero/core'
|
|
2
|
+
import { cliProxy } from '@mcphero/mcp'
|
|
3
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
4
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
8
|
+
.adapter(cliProxy({ url: new URL('http://localhost:8080/mcp') }))
|
|
9
|
+
.action(HelloAction)
|
|
10
|
+
.action(TaskAction)
|
|
11
|
+
.start()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main()
|
package/src/fastify.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mcphero } from '@mcphero/core'
|
|
2
|
+
import { fastify } from '@mcphero/fastify'
|
|
3
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
4
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
8
|
+
.adapter(fastify({ host: 'localhost', port: 8080, logger: true }))
|
|
9
|
+
.action(HelloAction)
|
|
10
|
+
.action(TaskAction)
|
|
11
|
+
.start()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main()
|
package/src/http.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mcphero } from '@mcphero/core'
|
|
2
|
+
import { http } from '@mcphero/mcp'
|
|
3
|
+
import { randomUUID } from 'crypto'
|
|
4
|
+
import { AdminAction } from './actions/AdminAction.js'
|
|
5
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
6
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
10
|
+
.set('sessionId', randomUUID)
|
|
11
|
+
.adapter(http({ host: 'localhost', port: 8080, allowedHosts: ['localhost'] }))
|
|
12
|
+
.action(HelloAction)
|
|
13
|
+
.action(TaskAction)
|
|
14
|
+
.action(AdminAction)
|
|
15
|
+
.start()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
main()
|
package/src/stdio.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mcphero } from '@mcphero/core'
|
|
2
|
+
import { stdio } from '@mcphero/mcp'
|
|
3
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
4
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
8
|
+
.adapter(stdio())
|
|
9
|
+
.action(HelloAction)
|
|
10
|
+
.action(TaskAction)
|
|
11
|
+
.start()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main()
|
package/src/vercel.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Example: Vercel/Next.js App Router route handler
|
|
2
|
+
// File would be at: app/api/mcp/route.ts in a Next.js project
|
|
3
|
+
|
|
4
|
+
import { mcphero } from '@mcphero/core'
|
|
5
|
+
import { vercel } from '@mcphero/vercel'
|
|
6
|
+
import { HelloAction } from './actions/HelloAction.js'
|
|
7
|
+
import { TaskAction } from './actions/TaskAction.js'
|
|
8
|
+
|
|
9
|
+
const { adapter, GET, POST, DELETE } = vercel()
|
|
10
|
+
|
|
11
|
+
await mcphero({ name: 'mcphero', description: 'MCPHero', version: '1.0.0' })
|
|
12
|
+
.adapter(adapter)
|
|
13
|
+
.action(HelloAction)
|
|
14
|
+
.action(TaskAction)
|
|
15
|
+
.start()
|
|
16
|
+
|
|
17
|
+
export { GET, POST, DELETE }
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"outDir": "build",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"declarationMap": true,
|
|
17
|
+
"sourceMap": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src"],
|
|
20
|
+
"exclude": ["node_modules", "build"]
|
|
21
|
+
}
|