@svedum/mcp-yandex-direct 0.0.0-stage → 0.1.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 +27 -2
- package/dist/auth.js +91 -0
- package/dist/client.js +661 -0
- package/dist/clientLogin.js +89 -0
- package/dist/config.js +55 -0
- package/dist/credentials.js +29 -0
- package/dist/index.js +157 -0
- package/dist/lossless.js +63 -0
- package/dist/operation.js +109 -0
- package/dist/telemetry.js +44 -0
- package/dist/tools/account.js +85 -0
- package/dist/tools/adGroups.js +126 -0
- package/dist/tools/ads.js +185 -0
- package/dist/tools/assets.js +142 -0
- package/dist/tools/auth.js +16 -0
- package/dist/tools/bidModifiers.js +211 -0
- package/dist/tools/campaigns.js +239 -0
- package/dist/tools/clients.js +362 -0
- package/dist/tools/dictionaries.js +74 -0
- package/dist/tools/excludedSites.js +65 -0
- package/dist/tools/keywords.js +150 -0
- package/dist/tools/listEdit.js +82 -0
- package/dist/tools/media.js +254 -0
- package/dist/tools/negativeKeywords.js +59 -0
- package/dist/tools/raw.js +48 -0
- package/dist/tools/statistics.aggregate.js +294 -0
- package/dist/tools/statistics.compare.js +111 -0
- package/dist/tools/statistics.js +324 -0
- package/dist/tools/strategy.js +131 -0
- package/dist/tools/util.js +280 -0
- package/dist/types.js +98 -0
- package/npm-shrinkwrap.json +1717 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gistrec
|
|
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
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @svedum/mcp-yandex-direct
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Форк [mcp-yandex-direct](https://github.com/askads/mcp-yandex-direct) (MIT, Aleksandr Kovalko) под схему OAuth платформы **Сведум**.
|
|
4
|
+
|
|
5
|
+
## Авторизация
|
|
6
|
+
|
|
7
|
+
Токен берётся в таком порядке:
|
|
8
|
+
|
|
9
|
+
1. **`YANDEX_DIRECT_TOKEN`** — переменная окружения в конфигурации MCP (удобно для CI и внешних клиентов).
|
|
10
|
+
2. **Файл хоста** — путь в `PLUGIN_OAUTH_CREDENTIALS_PATH`, JSON: `{ "access_token": "...", "expiry_date"?: число_ms }`. Файл пишет Сведум после OAuth; обновление токена делает платформа, не этот пакет.
|
|
11
|
+
|
|
12
|
+
В Сведуме: **Персонализация → Подключения** (или «Настроить» у интеграции Яндекс Директ).
|
|
13
|
+
|
|
14
|
+
Инструменты `start_login` / `finish_login` / `logout` из upstream удалены.
|
|
15
|
+
|
|
16
|
+
## Запуск
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install
|
|
20
|
+
npm run build
|
|
21
|
+
npx @svedum/mcp-yandex-direct
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Upstream
|
|
25
|
+
|
|
26
|
+
Исходный проект: https://github.com/askads/mcp-yandex-direct
|
|
27
|
+
|
|
28
|
+
Телеметрия Ask Ads отключена; лицензия MIT без изменений.
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { credentialsPath, readCredentials } from "./credentials.js";
|
|
2
|
+
/**
|
|
3
|
+
* Raised when a tool needs a token and none is available. The message is what the
|
|
4
|
+
* calling model relays to the user — it must name Svedum OAuth and YANDEX_DIRECT_TOKEN.
|
|
5
|
+
*/
|
|
6
|
+
export class AuthRequiredError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "AuthRequiredError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Treat the token as expired this long before the stated expiry. */
|
|
13
|
+
const EXPIRY_LEEWAY_MS = 60_000;
|
|
14
|
+
export const RELOGIN_MESSAGE = "Сохранённый токен Яндекс Директа больше не действует: истёк срок или доступ отозван. " +
|
|
15
|
+
"Обновление делает платформа Сведума — подключите аккаунт заново в Сведуме " +
|
|
16
|
+
"(Персонализация → Подключения) или задайте YANDEX_DIRECT_TOKEN и перезапустите MCP.";
|
|
17
|
+
export const NOT_CONNECTED_MESSAGE = "Яндекс Директ не подключён: нет токена доступа. " +
|
|
18
|
+
"Это не сбой сети — повторный вызов не поможет, нужно подключение. " +
|
|
19
|
+
"Войдите через «Настроить» в Сведуме (Персонализация → Подключения) или задайте " +
|
|
20
|
+
"переменную окружения YANDEX_DIRECT_TOKEN в конфигурации MCP и перезапустите сервер.";
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the access token for every request. Order: YANDEX_DIRECT_TOKEN (constructor/env),
|
|
23
|
+
* then PLUGIN_OAUTH_CREDENTIALS_PATH. The file is re-read each time so a host refresh
|
|
24
|
+
* takes effect without restarting the process.
|
|
25
|
+
*/
|
|
26
|
+
export class TokenStore {
|
|
27
|
+
envToken;
|
|
28
|
+
constructor(envToken) {
|
|
29
|
+
this.envToken = envToken;
|
|
30
|
+
}
|
|
31
|
+
hasToken() {
|
|
32
|
+
if (this.envToken)
|
|
33
|
+
return true;
|
|
34
|
+
return Boolean(readCredentials());
|
|
35
|
+
}
|
|
36
|
+
async getToken() {
|
|
37
|
+
if (this.envToken)
|
|
38
|
+
return this.envToken;
|
|
39
|
+
const stored = readCredentials();
|
|
40
|
+
if (!stored)
|
|
41
|
+
throw new AuthRequiredError(NOT_CONNECTED_MESSAGE);
|
|
42
|
+
if (isExpired(stored))
|
|
43
|
+
throw new AuthRequiredError(RELOGIN_MESSAGE);
|
|
44
|
+
return stored.access_token;
|
|
45
|
+
}
|
|
46
|
+
canRefresh() {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
usesStoredToken() {
|
|
50
|
+
return !this.envToken && Boolean(readCredentials());
|
|
51
|
+
}
|
|
52
|
+
/** Token refresh is owned by the Svedum platform — never performed here. */
|
|
53
|
+
async refresh() {
|
|
54
|
+
throw new AuthRequiredError(RELOGIN_MESSAGE);
|
|
55
|
+
}
|
|
56
|
+
/** No-op: the host writes credentials; this package never persists tokens. */
|
|
57
|
+
save(_response) {
|
|
58
|
+
const stored = readCredentials();
|
|
59
|
+
if (!stored)
|
|
60
|
+
throw new AuthRequiredError(NOT_CONNECTED_MESSAGE);
|
|
61
|
+
return stored;
|
|
62
|
+
}
|
|
63
|
+
/** No-op: disconnect via Svedum or remove YANDEX_DIRECT_TOKEN from MCP config. */
|
|
64
|
+
logout() {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
status() {
|
|
68
|
+
const path = credentialsPath();
|
|
69
|
+
if (this.envToken) {
|
|
70
|
+
return { configured: true, source: "env", canRefresh: false, path };
|
|
71
|
+
}
|
|
72
|
+
const stored = readCredentials();
|
|
73
|
+
if (!stored)
|
|
74
|
+
return { configured: false, canRefresh: false, path };
|
|
75
|
+
const expiry = stored.expiry_date ?? stored.expires_at;
|
|
76
|
+
return {
|
|
77
|
+
configured: true,
|
|
78
|
+
source: "stored",
|
|
79
|
+
expiresAt: expiry !== undefined ? new Date(expiry).toISOString() : undefined,
|
|
80
|
+
obtainedAt: stored.obtained_at !== undefined ? new Date(stored.obtained_at).toISOString() : undefined,
|
|
81
|
+
canRefresh: false,
|
|
82
|
+
path,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function isExpired(stored, now = Date.now()) {
|
|
87
|
+
const expiry = stored.expiry_date ?? stored.expires_at;
|
|
88
|
+
if (expiry === undefined)
|
|
89
|
+
return false;
|
|
90
|
+
return expiry - EXPIRY_LEEWAY_MS <= now;
|
|
91
|
+
}
|