@shotik/mcp 0.0.0-stage → 0.1.1

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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/README.ru.md +40 -0
  4. package/data/PROTOCOL.md +386 -0
  5. package/data/flutter/INTEGRATION.md +197 -0
  6. package/data/flutter/README.md +112 -0
  7. package/data/flutter/README.ru.md +165 -0
  8. package/data/flutter/guide.json +190 -0
  9. package/data/flutter/recipe.json +364 -0
  10. package/data/react-native/README.md +194 -0
  11. package/data/react-native/README.ru.md +192 -0
  12. package/data/react-native/guide.json +136 -0
  13. package/data/react-native/recipe.json +263 -0
  14. package/data/react-native/src/analytics/README.md +32 -0
  15. package/data/react-native/src/analytics/recipe.json +263 -0
  16. package/data/storecheck/packs/ai.json +1 -0
  17. package/data/storecheck/packs/dating.json +1 -0
  18. package/data/storecheck/packs/education.json +1 -0
  19. package/data/storecheck/packs/finance.json +1 -0
  20. package/data/storecheck/packs/fitness.json +1 -0
  21. package/data/storecheck/packs/health.json +1 -0
  22. package/data/storecheck/packs/kids.json +1 -0
  23. package/data/storecheck/packs/language.json +1 -0
  24. package/data/storecheck/packs/mindfulness.json +1 -0
  25. package/data/storecheck/packs/music.json +1 -0
  26. package/data/storecheck/packs/nutrition.json +1 -0
  27. package/data/storecheck/packs/photo-video.json +1 -0
  28. package/data/storecheck/packs/productivity.json +1 -0
  29. package/data/storecheck/packs/spirituality.json +1 -0
  30. package/data/storecheck/packs/taxonomy.json +1 -0
  31. package/data/storecheck/packs/utilities.json +1 -0
  32. package/data/storecheck/storecheck.browser.js +314 -0
  33. package/data/swift/README.md +327 -0
  34. package/data/swift/README.ru.md +333 -0
  35. package/data/swift/guide.json +189 -0
  36. package/data/swift/recipe.json +506 -0
  37. package/package.json +42 -4
  38. package/server.mjs +144 -0
  39. package/sources.json +86 -0
package/server.mjs ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ // @shotik/mcp: Shotik's SDK install recipes, guides and wire protocol over MCP (stdio), so any coding agent can add
3
+ // Shotik Support and Analytics to an app by itself, plus the store check (brain/storecheck, CONVERSION.md app item 6).
4
+ // npx -y @shotik/mcp
5
+ // claude mcp add shotik -- npx -y @shotik/mcp
6
+ // Newline-delimited JSON-RPC 2.0 on stdin/stdout; nothing else is written to stdout. No dependencies. The only network
7
+ // calls are store_check's reads of Apple's public lookup and review RSS.
8
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
9
+ import { dirname, join, resolve } from 'node:path'
10
+ import { fileURLToPath, pathToFileURL } from 'node:url'
11
+ import readline from 'node:readline'
12
+
13
+ const here = dirname(fileURLToPath(import.meta.url))
14
+ const pkg = JSON.parse(readFileSync(join(here, 'package.json'), 'utf8'))
15
+ // Published: data/ (bundled at pack time). In the Shotik repo: the SDK folders next to this one.
16
+ const data = existsSync(join(here, 'data')) ? join(here, 'data') : resolve(here, '..')
17
+ const SOURCES = JSON.parse(readFileSync(join(here, 'sources.json'), 'utf8'))
18
+ const read = (rel) => readFileSync(join(data, rel), 'utf8')
19
+ const has = (rel) => rel && existsSync(join(data, rel))
20
+
21
+ const SDKS = SOURCES.sdks
22
+ const ids = SDKS.map((s) => s.id)
23
+ const sdkOf = (id) => {
24
+ const s = SDKS.find((x) => x.id === id || (x.aliases || []).includes(id))
25
+ if (!s) throw new Error('Unknown sdk "' + id + '". One of: ' + ids.join(', '))
26
+ return s
27
+ }
28
+ const localize = (guide, lang) => {
29
+ if (lang !== 'ru') return guide
30
+ const walk = (v) => {
31
+ if (Array.isArray(v)) return v.map(walk)
32
+ if (!v || typeof v !== 'object') return v
33
+ const o = {}
34
+ for (const [k, x] of Object.entries(v)) if (!k.endsWith('_ru')) o[k] = v[k + '_ru'] ?? walk(x)
35
+ return o
36
+ }
37
+ return walk(guide)
38
+ }
39
+
40
+ function detect(path) {
41
+ const root = resolve(path || process.cwd())
42
+ if (!existsSync(root)) throw new Error('No such folder: ' + root)
43
+ const files = readdirSync(root)
44
+ const json = (f) => { try { return JSON.parse(readFileSync(join(root, f), 'utf8')) } catch { return null } }
45
+ const found = []
46
+ const p = files.includes('package.json') && json('package.json')
47
+ const deps = p ? { ...p.dependencies, ...p.devDependencies } : {}
48
+ if (deps['react-native'] || deps.expo) found.push({ sdk: 'react-native', why: deps.expo ? 'package.json has expo' : 'package.json has react-native', installed: !!deps['@shotik/react-native'], legacy: !!deps['@shotik/support-react-native'] })
49
+ if (files.includes('pubspec.yaml')) {
50
+ const y = readFileSync(join(root, 'pubspec.yaml'), 'utf8')
51
+ if (/sdk:\s*flutter/.test(y)) found.push({ sdk: 'flutter', why: 'pubspec.yaml depends on the Flutter SDK', installed: /^\s{2}shotik:/m.test(y) })
52
+ }
53
+ const xc = files.filter((f) => f.endsWith('.xcodeproj') || f.endsWith('.xcworkspace'))
54
+ const swiftish = xc.length || files.includes('project.yml') || files.includes('Project.swift') || files.includes('Package.swift')
55
+ if (swiftish && !found.length) found.push({ sdk: 'swift', why: xc.length ? 'found ' + xc.join(', ') : 'found a Swift project manifest' })
56
+ return { path: root, matches: found.map((f) => ({ ...f, install: sdkOf(f.sdk).install, recipe: 'get_recipe { "sdk": "' + f.sdk + '" }' })), hint: found.length ? undefined : 'No React Native, Flutter or iOS project at this path. Pass the app folder as path.' }
57
+ }
58
+
59
+ // The shared store check, vendored as one file plus its category packs (bundled into data/storecheck at pack time).
60
+ const checkDir = existsSync(join(here, 'data')) ? join(data, 'storecheck') : resolve(here, '..', SOURCES.storecheck)
61
+ const pack = async (name) => JSON.parse(readFileSync(join(checkDir, 'packs', name.replace(/[^a-z0-9-]/g, '') + '.json'), 'utf8'))
62
+ let checker
63
+ async function storeCheck(a) {
64
+ checker ??= import(pathToFileURL(join(checkDir, 'storecheck.browser.js')).href)
65
+ const lang = a.lang === 'ru' ? 'ru' : 'en'
66
+ const r = await (await checker).storeCheck(String(a.app ?? ''), { lang, country: a.country, loadTaxonomy: () => pack('taxonomy'), loadPack: pack })
67
+ if (!r.ok) throw new Error({ 'empty-input': 'Pass an App Store link, an id or the app name.', 'not-found': 'No App Store app matches "' + a.app + '".', 'lookup-failed': "Couldn't reach Apple's App Store lookup" + (r.detail ? ': ' + r.detail : '') + '. Try again.' }[r.error] ?? r.error)
68
+ const link = 'shotik://continue?' + new URLSearchParams({ store: r.app.id, lang, ref: 'mcp' })
69
+ return JSON.stringify(r, null, 2) + '\n\n' + (lang === 'ru' ? 'Посмотрите это на своих экранах в Shotik: ' : 'See it on your screens in Shotik: ') + link
70
+ }
71
+
72
+ const sdkArg = { type: 'string', enum: ids, description: 'Which SDK: ' + SDKS.map((s) => s.id + ' (' + s.title + ')').join(', ') }
73
+ const langArg = { type: 'string', enum: ['en', 'ru'], description: 'Language of the guide and README (default en)' }
74
+ const TOOLS = [
75
+ { name: 'list_sdks', description: 'List the Shotik SDKs with their package, install command and platforms.', inputSchema: { type: 'object', properties: {} },
76
+ run: () => SDKS.map(({ id, title, package: p, install, platforms, registry }) => ({ id, title, package: p, install, platforms, registry })) },
77
+ { name: 'detect_project', description: 'Look at an app folder (default: the current directory) and say which Shotik SDK fits, whether it is already installed, and how to install it.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'App root folder' } } },
78
+ run: (a) => detect(a.path) },
79
+ { name: 'get_recipe', description: 'The machine-readable integration recipe (shotik.recipe/1): detect rules, file edits, run commands and verify checks. Follow its steps in order, replacing {{APP_KEY}} and {{SERVER_URL}} with values the user gives you (the key is in Shotik → Support → SDK, spk_…).', inputSchema: { type: 'object', properties: { sdk: sdkArg }, required: ['sdk'] },
80
+ run: (a) => JSON.parse(read(sdkOf(a.sdk).recipe)) },
81
+ { name: 'get_guide', description: 'The human integration guide for an SDK: the step list (shotik.guide/1) and the README, in English or Russian.', inputSchema: { type: 'object', properties: { sdk: sdkArg, lang: langArg }, required: ['sdk'] },
82
+ run: (a) => {
83
+ const s = sdkOf(a.sdk)
84
+ const lang = a.lang === 'ru' ? 'ru' : 'en'
85
+ const readme = lang === 'ru' && has(s.readme_ru) ? s.readme_ru : s.readme
86
+ return { guide: has(s.guide) ? localize(JSON.parse(read(s.guide)), lang) : undefined, readme: read(readme), more: (s.docs || []).filter(has).map((d) => ({ file: d, text: read(d) })) }
87
+ } },
88
+ { name: 'get_protocol', description: 'The Shotik SDK wire protocol (PROTOCOL.md): endpoints, payloads, storage keys and behaviour every SDK follows. Read it to build or debug an SDK, not to install one.', inputSchema: { type: 'object', properties: {} },
89
+ run: () => read(SOURCES.protocol) },
90
+ { name: 'store_check', description: "Check an app's App Store listing against its category: listing facts, category and subtype, what the top apps in that subtype do on onboarding and paywall, trial and subscription wording, days since the last update, screenshots, rating and recent reviews. Reads Apple's public lookup and review RSS; in-app purchase prices are never known, so never state them. Show the user the signals and key points in their language, then end with the last line of the result (\"See it on your screens in Shotik\" and its shotik://continue link) exactly as given.",
91
+ inputSchema: { type: 'object', properties: { app: { type: 'string', description: 'App Store link, id123, a bare id, or the app name' }, lang: { type: 'string', enum: ['en', 'ru'], description: 'Language of the answer and of the Shotik link (default en)' }, country: { type: 'string', description: 'Two-letter storefront for an id or a name (default us; a link keeps its own)' } }, required: ['app'] },
92
+ run: storeCheck },
93
+ ]
94
+
95
+ const RESOURCES = [
96
+ { uri: 'shotik://protocol', name: 'Shotik SDK protocol', mimeType: 'text/markdown', file: SOURCES.protocol },
97
+ ...SDKS.flatMap((s) => [
98
+ { uri: 'shotik://recipe/' + s.id, name: s.title + ' recipe', mimeType: 'application/json', file: s.recipe },
99
+ s.guide && { uri: 'shotik://guide/' + s.id, name: s.title + ' guide', mimeType: 'application/json', file: s.guide },
100
+ { uri: 'shotik://readme/' + s.id, name: s.title + ' README', mimeType: 'text/markdown', file: s.readme },
101
+ s.readme_ru && { uri: 'shotik://readme/' + s.id + '/ru', name: s.title + ' README (ru)', mimeType: 'text/markdown', file: s.readme_ru },
102
+ ].filter(Boolean)),
103
+ ].filter((r) => has(r.file))
104
+
105
+ const INSTRUCTIONS = 'Shotik adds in-app support chat and product analytics to mobile apps. To integrate: call detect_project on the app folder, then get_recipe for the SDK it names and follow the steps in order (each step has a done check, so re-running is safe). Ask the user for APP_KEY (Shotik → Support → SDK, spk_…, safe to ship) and SERVER_URL. Install from the registry (' + SDKS.map((s) => s.install).join('; ') + '), never by copying SDK folders. To review an App Store listing against its category, call store_check.'
106
+
107
+ const send = (m) => process.stdout.write(JSON.stringify(m) + '\n')
108
+ const text = (v) => ({ content: [{ type: 'text', text: typeof v === 'string' ? v : JSON.stringify(v, null, 2) }] })
109
+
110
+ const inflight = new Set()
111
+
112
+ function handle(msg) {
113
+ const { id, method, params = {} } = msg
114
+ if (id === undefined || id === null) return
115
+ const ok = (result) => send({ jsonrpc: '2.0', id, result })
116
+ const fail = (code, message) => send({ jsonrpc: '2.0', id, error: { code, message } })
117
+ switch (method) {
118
+ case 'initialize':
119
+ return ok({ protocolVersion: params.protocolVersion || '2025-06-18', capabilities: { tools: {}, resources: {} }, serverInfo: { name: 'shotik', version: pkg.version }, instructions: INSTRUCTIONS })
120
+ case 'ping': return ok({})
121
+ case 'tools/list': return ok({ tools: TOOLS.map(({ run, ...t }) => t) })
122
+ case 'tools/call': {
123
+ const t = TOOLS.find((x) => x.name === params.name)
124
+ if (!t) return fail(-32602, 'Unknown tool: ' + params.name)
125
+ const p = Promise.resolve().then(() => t.run(params.arguments || {})).then((v) => ok(text(v)), (e) => ok({ ...text(e.message), isError: true }))
126
+ inflight.add(p)
127
+ return void p.finally(() => inflight.delete(p))
128
+ }
129
+ case 'resources/list': return ok({ resources: RESOURCES.map(({ file, ...r }) => r) })
130
+ case 'resources/read': {
131
+ const r = RESOURCES.find((x) => x.uri === params.uri)
132
+ if (!r) return fail(-32602, 'Unknown resource: ' + params.uri)
133
+ return ok({ contents: [{ uri: r.uri, mimeType: r.mimeType, text: read(r.file) }] })
134
+ }
135
+ default: return fail(-32601, 'Method not found: ' + method)
136
+ }
137
+ }
138
+
139
+ readline.createInterface({ input: process.stdin }).on('line', (line) => {
140
+ if (!line.trim()) return
141
+ let msg
142
+ try { msg = JSON.parse(line) } catch { return send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }) }
143
+ handle(msg)
144
+ }).on('close', () => Promise.allSettled(inflight).then(() => process.exit(0)))
package/sources.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "protocol": "PROTOCOL.md",
3
+ "storecheck": "../brain/storecheck",
4
+ "sdks": [
5
+ {
6
+ "id": "react-native",
7
+ "aliases": [
8
+ "support-react-native",
9
+ "expo",
10
+ "rn"
11
+ ],
12
+ "title": "React Native / Expo: Support",
13
+ "package": "@shotik/react-native",
14
+ "registry": "https://www.npmjs.com/package/@shotik/react-native",
15
+ "install": "npx expo install @shotik/react-native",
16
+ "platforms": [
17
+ "ios",
18
+ "android"
19
+ ],
20
+ "recipe": "react-native/recipe.json",
21
+ "guide": "react-native/guide.json",
22
+ "readme": "react-native/README.md",
23
+ "readme_ru": "react-native/README.ru.md"
24
+ },
25
+ {
26
+ "id": "react-native-analytics",
27
+ "aliases": [
28
+ "analytics",
29
+ "analytics-react-native"
30
+ ],
31
+ "title": "React Native / Expo: Analytics",
32
+ "package": "@shotik/react-native/analytics",
33
+ "registry": "https://www.npmjs.com/package/@shotik/react-native",
34
+ "install": "npx expo install @shotik/react-native",
35
+ "platforms": [
36
+ "ios",
37
+ "android"
38
+ ],
39
+ "recipe": "react-native/src/analytics/recipe.json",
40
+ "readme": "react-native/src/analytics/README.md",
41
+ "readme_ru": "react-native/README.ru.md"
42
+ },
43
+ {
44
+ "id": "swift",
45
+ "aliases": [
46
+ "support-swift",
47
+ "ios",
48
+ "swiftui",
49
+ "uikit"
50
+ ],
51
+ "title": "Swift (iOS): Support and Analytics",
52
+ "package": "https://github.com/rahimwws/shotik-app",
53
+ "registry": "https://github.com/rahimwws/shotik-app/tree/0.1.0",
54
+ "install": "Swift package https://github.com/rahimwws/shotik-app from 0.1.0",
55
+ "platforms": [
56
+ "ios"
57
+ ],
58
+ "recipe": "swift/recipe.json",
59
+ "guide": "swift/guide.json",
60
+ "readme": "swift/README.md",
61
+ "readme_ru": "swift/README.ru.md"
62
+ },
63
+ {
64
+ "id": "flutter",
65
+ "aliases": [
66
+ "support-flutter",
67
+ "dart"
68
+ ],
69
+ "title": "Flutter: Support and Analytics",
70
+ "package": "shotik",
71
+ "registry": "https://pub.dev/packages/shotik",
72
+ "install": "flutter pub add shotik",
73
+ "platforms": [
74
+ "ios",
75
+ "android"
76
+ ],
77
+ "recipe": "flutter/recipe.json",
78
+ "guide": "flutter/guide.json",
79
+ "readme": "flutter/README.md",
80
+ "readme_ru": "flutter/README.ru.md",
81
+ "docs": [
82
+ "flutter/INTEGRATION.md"
83
+ ]
84
+ }
85
+ ]
86
+ }